Re: Memory leak - What the ...?

From: Hyman Rosen (hyrosen_at_mail.com)
Date: 10/14/04


Date: Thu, 14 Oct 2004 13:21:05 -0400

Martin Krischik wrote:
> Either you use the build in bit copy constructor and
> assignment operator or you define you.

The compiler-generated copy constructor and assignment
operator are defined to do memberwise copying, not bit
copies. The compiler may implement these more efficiently
as it chooses, but it can do that for user-defined ones
as well.

> 2nd: It is an easy mistake to forget the copy constructor or assignment
> operator when adding a new attribute. And please don't tell me you might
> *sometimes* want that behaviour.

You should avoid writing your own assignment and copy
constructors when you possibly can, and use the default
ones. If some member requires special copy handling,
then it should be of a type which encapsulates this.
Then adding new members doesn't require making any
changes to the copying code.



Relevant Pages

  • Re: operator=
    ... Compiler will supply - unless the programmer decides to do it - the ... It isn't required in an assignment: ... You will find that the code within the copy constructor and assignment ... Aside from the inlined code [i.e. the member ...
    (alt.comp.lang.learn.c-cpp)
  • Re: basic basic ada question
    ... Assignment statements, you mean. ... a name of the primitive operation. ... constructor or alternatively object state changer. ... Surely the calls must be inserted by the compiler. ...
    (comp.lang.ada)
  • Re: Copy constructor
    ... If I had ICloneablethen the Clone method would return a ... And the compiler would not detect it. ... the only advantage you have with a "copy" constructor is ... The temptation to override the assignment operator in all my classes to ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Initialization notation
    ... >> compiler) ... The assignment operator doesn't seem to be necessary... ... abbreviation of th first notation, since it doesn't impose any restrictions ... on the class (except the existance of the used constructor;) ...
    (comp.lang.cpp)
  • Re: Inheritted copy constructor???
    ... this seems to indicate that the copy constructor for B is being ... which seems to me like it contradicts Mr. Stroustrup. ... and exactly the same for the copy assignment. ... relying on the default memberwise copies for all classes in a hierarchy)? ...
    (alt.comp.lang.learn.c-cpp)