From: Giovanni Dicanio on 11 May 2010 03:43 "Frank" <jerk(a)gmx.de> ha scritto nel messaggio news:98d7f241-37f7-4d59-b6f9-40956bb9716c(a)24g2000yqy.googlegroups.com... > I see... so the copy constructor of C1 won't invoke > the assignment operators of its members to initialize > them like I thought? Doug was very clear in his post: the copy constructor of C1 will just invoke the *copy constructors* (not operator=) of its data members. Giovanni
From: Frank on 11 May 2010 04:59 Giovanni Dicanio wrote: > Doug was very clear in his post: the copy constructor of C1 will just invoke > the *copy constructors* (not operator=) of its data members. Ok... so the question remains: Why doesn't C1 have a copy constructor anymore from the moment I wrote one for one of its members?
From: Goran on 11 May 2010 07:46 On May 11, 10:59 am, Frank <j...(a)gmx.de> wrote: > Giovanni Dicanio wrote: > > Doug was very clear in his post: the copy constructor of C1 will just invoke > > the *copy constructors* (not operator=) of its data members. > > Ok... so the question remains: Why doesn't C1 have a > copy constructor anymore from the moment I wrote one > for one of its members? Perhaps you should show the code that exhibits the behavior. Also, you should try to compile it with e.g. comeau online. Goran.
From: Frank on 11 May 2010 09:18 Goran wrote: > On May 11, 10:59 am, Frank <j...(a)gmx.de> wrote: > > > Giovanni Dicanio wrote: > > > Doug was very clear in his post: the copy constructor of C1 will just invoke > > > the *copy constructors* (not operator=) of its data members. > > > Ok... so the question remains: Why doesn't C1 have a > > copy constructor anymore from the moment I wrote one > > for one of its members? > > Perhaps you should show the code that exhibits the behavior. Also, you > should try to compile it with e.g. comeau online. Yes, thanks, I'll strip it down a bit because I found a solution now but don't understand it - it works if I make the parameter of the copy constructor of C2 a "const": This works: class C2 { ... C2(const C2 &cRHS) { AssignData(cRHS); } } This doesn't work: class C2 { ... C2(C2 &cRHS) { AssignData(cRHS); } }
From: Giovanni Dicanio on 11 May 2010 10:26
"Frank" <jerk(a)gmx.de> wrote: > This works: > > class C2 > { > ... > > C2(const C2 &cRHS) > This doesn't work: > > class C2 > { > ... > > C2(C2 &cRHS) I think this is because the usual pattern for copy ctor for class X is: X::X( const X & ) Giovanni |