Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Q: c'tor and assignment operators

Reply
Thread Tools

Q: c'tor and assignment operators

 
 
Jakob Bieling
Guest
Posts: n/a
 
      01-16-2005
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!
--
jb

(reply address in rot13, unscramble first)


 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      01-16-2005
Jakob Bieling wrote:

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it a good practice to call the destructor explicitly and use placement new(this) in assignment operators? Michael Tsang C++ 8 12-14-2009 07:43 PM
short-circuit evaluation and assignment operators Anthony Paul C Programming 5 06-06-2009 06:49 PM
pointers and assignment operators, basic question Jeff Bender C++ 6 06-08-2007 10:26 PM
Possible constant assignment operators ":=" and "::=" for Python tsaar2003@yahoo.com Python 25 05-18-2006 05:27 AM
Composite Assignment Operators for enums David Rasmussen C++ 3 02-24-2004 06:21 PM



Advertisments