Skip to main content
GameDev.net gamedev.net
🔒 Locked

style: assignment operator verus functional notation

Started by Whitty Dec 11, 2002 at 12:44 AM 6 replies 750+ views
Original Post
Whitty
Whitty
Just curious, when is it considered(if at all) in good style to use the assignment operator, and under what circumstances is better accepted to use functional notation? ---------- I am the dancing tooth fairy and I have come to take your teeth!
----------I am the dancing tooth fairy and I have come to take your teeth!@#$ HAR HAR HAR
Zipster
Zipster
By functional notation, I assume you mean int i(5); I usually only that notation in a initialization list, pretty much because you have to (), but otherwise, not really at all. If anything, it''s an extra character to type
Whitty
Whitty
Actually, you also have to use it in the circumstance of using an explicit constructor.

----------
I am the dancing tooth fairy and I have come to take your teeth!
----------I am the dancing tooth fairy and I have come to take your teeth!@#$ HAR HAR HAR
Zipster
Zipster
Right, that's also known as an initialization list (as opposed to equal-operator). Or rather, initializer list. Bah, same thing to me I was thinking about initialization lists when I wrote the "because you have to" part.

[edited by - Zipster on December 11, 2002 4:17:11 AM]
Fruny
Fruny
Direct constructor calls also let you create temporaries my_func( my_type() );


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | Free C++ IDE. ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Boost C++ Lib ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Zipster
Zipster
I guess so. Having to remember that initialization is a special case could get a bit confusing.
Brobanx
Brobanx
When initializing a variable, assignment actually calls the copy constructor rather than a default constructor.

Take for example a class foo.


foo bob;
foo jack = bob;
foo george(bob);


the last two lines of that code both call the copy constructor, sending bob as a reference.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.