Re: Use of copy constructor in pass by value

From: Risto Lankinen (rlankine_at_hotmail.com)
Date: 02/05/04


Date: Thu, 05 Feb 2004 13:08:20 GMT


"Rolf Magnus" <ramagnus@t-online.de> wrote in message
news:bvt7vu$9o6$00$1@news.t-online.com...
> madhukar_bm wrote:
>
> > We know that copy constructor is used if a class object is passed by
> > value to a function, is there any logic behind the use of copy
> > constructor as assignment operator could also have been used instead
> > of copy constructor
>
> What would it assign to? You have to create a new object that is a copy
> of an existing one, and that's exactly what the copy constructor is
> for. The assignment operator is for making an existing object a copy of
> another one.

This is in fact an interesting question. If copy constructor is
inaccessible, is the system allowed to default-construct, and
then assign, to simulate the effect of copy construction when
it implicitly needs to? If not, would it make sense to allow it
to happen?

 - Risto -



Relevant Pages

  • Re: Questions of copy constructor
    ... >> have a copy constructor and assignment operator. ... assignment operator is that a class manages or "owns" some resource. ... Such classes often contain pointers, but the presence of a pointer ... >> itself has a pointer member or not? ...
    (comp.lang.cpp)
  • Re: Does std::map provides a copy assignment operator?
    ... assignment and copy constructor. ... > If the compiler-manufactured assignment operator (and also copy ... > destructors if the compiler-generated version does the wrong thing. ... > because the compiler versions will do the right thing for and call the ...
    (microsoft.public.vc.stl)
  • Re: implementation details
    ... > to investigating the importance of templates. ... > Retrieve then I'd like to implement some sort of overrun check. ... > an implementation of the assignment operator that'll compare two ... > buffers and a copy constructor that'll do just that. ...
    (comp.lang.cpp)
  • Re: bitset assignment & copy constructor
    ... This is part of C++ language specification, not some kind of implementation-specific behavior. ... So whenever I provid a copy constructor or assignment operator in my derived STL class the compiler will take mines, in case I don't the compiler takes the default ones for me correct? ...
    (microsoft.public.vc.stl)
  • Re: constructor and destructor
    ... I added a function for assignment operator and a copy ... > constructor and obtained the correct output. ... I had assumed the other way round, that the destructor is ... > Am I not calling the constructor explicitly here? ...
    (comp.lang.cpp)