Q: c'tor and assignment operators

J

Jakob Bieling

Hi,

Recently, I have seen code where the assignment operator has a return
type 'void'. I do understand that it is a 'bad idea' in the sense that I am
limiting myself, when using that operator= (ie. v = w = x would not be
possible). But I asked myself if this is legal. Even though I would not know
why this should be illegal (Standard did not give me a clue either), I am
not 100% sure.

Second question is about (copy) c'tors: Am I right in saying that a copy
c'tor is provided by the compiler whenever there is now copy c'tor (but
there may be other c'tors)? Also, a default c'tor is only provided by the
compiler, when there is no c'tor at all, correct?

Thanks!
 
R

Rolf Magnus

Jakob said:
Hi,

Recently, I have seen code where the assignment operator has a return
type 'void'. I do understand that it is a 'bad idea' in the sense that I
am limiting myself, when using that operator= (ie. v = w = x would not be
possible). But I asked myself if this is legal. Even though I would not
know why this should be illegal (Standard did not give me a clue either),
I am not 100% sure.

Yes, it is legal. However,AFAIK, you might not be able to use that class as
element type for standard containers since they could depend on the
assignment operator returning something.
Second question is about (copy) c'tors: Am I right in saying that a
copy c'tor is provided by the compiler whenever there is now copy
c'tor (but there may be other c'tors)?
Yes.

Also, a default c'tor is only provided by the compiler, when there is
no c'tor at all, correct?

.... when there is no _user-defined_ constructor...
Aside from that, it's correct.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top