Copy cstor and operator=

E

eas

Can call copy constructor inside operator=? Can call operator= from inside
constructor?

My understanding is both members in a class contain a "this" pointer. Even
if the class has a member of pointer, for example, char* (I mention this
because that's one reason we need copy constructor/assignment operator),
this will not affect since during the above said calling, the pointer member
will be assigned or initialized.

However I may miss something here. Could somebody correct me if I am wrong?

Thanks in advance!
 
V

Victor Bazarov

eas said:
Can call copy constructor inside operator=?

Call, no, since you cannot _call_ any constructor. Cause invocation, yes.
Can call operator= from inside
constructor?

Yes. However, watch out for infinite recursion.
My understanding is both members in a class contain a "this" pointer.

The 'this' pointer is defined in all non-static members.
Even
if the class has a member of pointer, for example, char* (I mention this
because that's one reason we need copy constructor/assignment operator),
this will not affect since during the above said calling, the pointer member
will be assigned or initialized.

I am not sure I perfectly understand the above statement, but it sounds
about right.
However I may miss something here. Could somebody correct me if I am
wrong?

Hmm... I've not discovered anything inherently wrong (except that you cannot
_call_ a constructor).

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,416
Latest member
LionelQ387

Latest Threads

Top