Simple question about copy constructor and assignment operator

Hi,
I have a simple question about copy constructors and assignement operators, but i don’t seem to find a clear answer.
When you overload the default ones, in order to apply specific copies for some members, do those overloads have to copy all the members of the object, or can you just specify a copy method for specific members and the other members are automatically copied with their assignmenet operator?

Regards
O.B.
You must copy all members, including calling the copy ctor and assignment operators of any parent classes.
OK, thanks,
An other question, related the copy constructors,

I have a structure S containing on object of class C.
I added a copy constructor to C, and then the compiler (VC++2005) complained (error, not warning) that it didn’t find the copy constructor of S. Is it mandatory for a class/struct to have a copy constructor when one of it's member has one?
No. S does not need a copy ctor.

The only way I can see that being a problem was if C's copy ctor was ill formed (maybe you forgot a const?)

Although, if you add a copy ctor to S, you might also need to add a default ctor to S. I know if you add a ctor to a class, the built-in default ctor no longer applies. I'm not sure if that rule applies to the copy ctor or not....

In any event, the below should work just fine:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class C
{
public:
  C()
  {
  }

  C(const C& c)
  {
    // copy construct here
  }
};

struct S
{
  C foo;
};

int main()
{
  S s;

  S s2(s);

  return 0;
}
Topic archived. No new replies allowed.