copy constructor for const members

Oct 9, 2008 at 2:47pm
hi everyone;
i need to know how to make a copy constructor that let me copy a value of a const member
thanks
Oct 9, 2008 at 6:45pm
Under most circumstances the default copy constructor provided by the compiler (member-wise copy) is sufficient. The cases where it is not sufficient are:

1) You have a very old compiler which provides a bit-wise copy instead;
2) Your class contains pointer members, and you need to perform a deep copy.

If you need to write a copy constructor, the general form is:

1
2
3
4
5
class Foo {
  Foo( const Foo& f ) :
      mem1( f.mem1 ), mem2( f.mem2 ) /* etc */
  {}
};


where mem1 and mem2 are data members of Foo, which can be const
members, non-const members, const references or non-const references.
Oct 10, 2008 at 10:02pm
thank you
i was not sure if i could do it in this way.
it really solved my problems
Topic archived. No new replies allowed.