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 3997292
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:23:02+00:00 2026-05-20T07:23:02+00:00

I have a vector of A objects. class A contains a member object of

  • 0

I have a vector of A objects. class A contains a member object of type B. class B contains a statically declared array of bool. When I copy an A object into the vector, the values in the bool array are lost. I though this shouldn’t be a problem because the array of bool is statically declared. Do I need to handle this using a copy constructor?

class B
{
public:
    bool theArray[5] ;

    B(bool x) {theArray[1] = x;};
    B(){};

};

class A
{
public:
    B obj_B;

    A() : obj_B(1) {};
    A(A const &origin) : obj_B(origin.obj_B){};
};

int main () 
{
    std::vector <A> someAs;
    for(int q=0;q<10;q++)
        someAs.push_back(A());

    for(int q=0;q<10;q++)
        std::cout << someAs[q].obj_B.theArray[1] << std::endl;
}
  • 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-20T07:23:03+00:00Added an answer on May 20, 2026 at 7:23 am

    You shouldn’t need to define a copy constructor to do this. I’m not sure what you mean by “static arrays,” since there are two meanings, but neither require a copy constructor.

    If you mean “array that’s statically sized,” like this:

    class MyClass {
    private:
        bool myArray[137];
    };
    

    Then the default copy constructor will do a memberwise copy of the elements from the object being copied.

    If you mean “a static array of bools,” like this:

    class MyClass {
    private:
        static bool myArray[137];
    };
    

    Then the copy constructor won’t touch this array because it’s shared across all instances of the class.

    If your array of bools is getting corrupted, you might have a memory corruption bug on your hands, perhaps by reading off the end of an array or dereferencing a bad pointer. I’d look into this, since the default copy behavior will indeed give you what you want.

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

Sidebar

Related Questions

I have a vector-like class that contains an array of objects of type T
I have a vector called actorVector which stores an array of objects of type
I have a class that contains a vector of object pointers. I have a
I have a class that has a vector of another class objects as a
I have a class with a vector of pointers to objects. I've introduced some
So I have a container(any kind, probably std::map or std::vector) which contains objects of
I have a file that contains java serialized objects like Vector. I have stored
I have a vector declared as: vector<Curve> workingSet; Curve is a class I've created
I have a class that contains a dynamically allocated array, say class A {
I have a vector with some (among other classobjects) multiple added objects class Foo

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.