A warning would be nice

posted in MyJournal.lnk
Published June 15, 2005
Advertisement
Grrrr....

class X { }class M{ public:  M(X* x) {}}class Y{ private:  M m;  X* x; public:  Y(X* nx):   x(nx),   m(x) {}}


The above code raises an exception when attempting to create a new class Y. The order of attributes is M, X*. In the constructor, x is initialised with nx, then m is initialised with the class attribute x.. this is not the case. Initialisation order is done in order of specification in code,

so the constructor actually executes like so:

Y(X* nx): m(x), x(nx) {}


As specified in C++ standard.

VC++ 2003 does not give any warnings or errors during compilation about using attributes before they've been assigned a value, it'd be helpful if it did :(
0 likes 2 comments

Comments

Zorbfish
Just to clarify, are you compiling at the highest warning level (/W4)? I know on level 4 it will complain about using variables without initializing them.
June 15, 2005 09:19 AM
Zanthos
Thanks for that but unfortunately it still doesn't inform me that something will go horribly bad X(
June 15, 2005 12:49 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement