Q: c'tor and assignment operators

Discussion in 'C++' started by Jakob Bieling, Jan 16, 2005.

  1. 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)
     
    Jakob Bieling, Jan 16, 2005
    #1
    1. Advertising

  2. Jakob Bieling

    Rolf Magnus Guest

    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.
     
    Rolf Magnus, Jan 16, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raffael Vogler
    Replies:
    8
    Views:
    1,162
    Chris Uppal
    Nov 30, 2003
  2. Replies:
    25
    Views:
    690
    Steve Holden
    May 18, 2006
  3. Chameleon

    new and throw in c'tor

    Chameleon, Jan 10, 2007, in forum: C++
    Replies:
    3
    Views:
    306
    Peter
    Jan 10, 2007
  4. Chameleon

    boost::thread and class d'tor

    Chameleon, Jan 7, 2008, in forum: C++
    Replies:
    2
    Views:
    395
    James Kanze
    Jan 7, 2008
  5. [rob desbois]
    Replies:
    15
    Views:
    520
    [rob desbois]
    Feb 4, 2008
Loading...

Share This Page