Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualCornstalks

Posted 14 June 2013 - 05:53 PM

If you're got access to C++11's initializer lists, there's no magic required. This functionality is now built into the language.

 

Also, that code doesn't call the assignment operator. Initialization upon creation is done not with the assignment operator, but with the constructor (and subsequently the copy constructor, though to extra copy is typically elided).

 

Long story short, that code you wrote will get handled as if it were written:

 

COORD position(COORD({0, 0, 0})); // operator= is never used

// Note the above copy often is elided, and thus the code becomes "COORD position({0, 0, 0});" (but the copy construct is still required to be available, or else you'll get a compile time error)

 

And unless you've got C++11's initializer lists, you can't do that.

 

As for your question, operator= is a binary operator, and cannot take any more (or less) than 2 arguments.


#3Cornstalks

Posted 14 June 2013 - 05:50 PM

If you're got access to C++11's initializer lists, there's no magic required. This functionality is now built into the language.

 

Also, that code doesn't call the assignment operator. Initialization upon creation is done not with the assignment operator, but with the constructor (and subsequently the copy constructor, though to extra copy is typically elided).

 

Long story short, that code you wrote will get handled as if it were written:

 

COORD position(COORD({0, 0, 0})); // operator= is never used

// Note the above copy often is elided, and thus the code becomes "COORD position({0, 0, 0});" (but the copy construct is still required to be available, or else you'll get a compile time error)

 

And unless you've got C++11's initializer lists, you can't do that.


#2Cornstalks

Posted 14 June 2013 - 05:50 PM

If you're got access to C++11's initializer lists, there's no magic required. This functionality is now built into the language.

 

Also, that code doesn't call the assignment operator. Initialization upon creation is done not with the assignment operator, but with the constructor (and subsequently the copy constructor, though to extra copy is typically elided).

 

Long story short, that code you wrote will get handled as if it were written:

 

COORD position(COORD({0, 0, 0})); // operator= is never used

// Note the above copy often is elided, and thus the code becomes "COORD position({0, 0, 0});"

 

And unless you've got C++11's initializer lists, you can't do that.


#1Cornstalks

Posted 14 June 2013 - 05:49 PM

If you're got access to C++11's initializer lists, there's no magic required. This functionality is now built into the language.

 

Also, that code doesn't call the assignment operator. Initialization upon creation is done not with the assignment operator, but with the constructor (and subsequently the copy constructor, though to extra copy is typically elided).

 

Long story short, that code you wrote will get handled as if it were written:

 

COORD position(COORD({0, 0, 0})); // operator= is never used

 

And unless you've got C++11's initializer lists, you can't do that.


PARTNERS