• entries
25
27
• views
14132

# A warning would be nice

295 views

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 :(

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.

Thanks for that but unfortunately it still doesn't inform me that something will go horribly bad X(

## Create an account

Register a new account