Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:51:28+00:00 2026-05-31T15:51:28+00:00

Hi I have a class which includes an array, I’m not passing this through

  • 0

Hi I have a class which includes an array, I’m not passing this through my class constuctor (could be going wrong here?) The array is just defined in the class then initialized in a read method.

But in the main I make an instance of the class like:

myClass myClass1;

Then do:

myClass1 = myClass2;

Now I use a bubble sort method on the first class instance like:

MyClass1.sort();

Now when I write both of these instances out to text after the sort they are both sorted?

I have had a read into shallow and deep copys, but I can’t understand why a method called after the shallow copy, would result in both of them being sorted? Is this expected behavoir?

a little more information:

In my class I just define the array as:

static string myArray[5];

then in a write method I write the 5 elements to it, is there a better way of doing this, I have to use a method to intialize it though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:51:29+00:00Added an answer on May 31, 2026 at 3:51 pm

    In my class I just define the array as:

    static string myArray[5];
    

    Should I declare it in the header, as its only declared in the cpp file? As its still copying both.

    If you declare that outside of a class definition it will be a global variable. There will only be one instance of it. You need to declare it inside the class, and not static:

    class MyClass1 {
        // other things...
        string myArray[5];
    };
    

    In any case, this kind of basic question is better answered by consulting a good C++ introductory book.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which is going to handle an array of objects of
I have a base class, which includes all other files. I can access this
I have class A which extends the Activity class. This class is in package
I have class Employee which is something like this. class Emp { int EmpID;
I have a class which is marked with a custom attribute, like this: public
I have an wrapping object array -in fact a matrix- which includes a checkbox,
After reading the android documentation about String, which includes this: This class is implemented
I am using C#. I have created a class which can be included in
So I have a class.. In its constructor I include the code which connects
I have class which have one public method Start , one private method and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.