Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

A warning would be nice

A warning would be nice

Zanthos
MyJournal.lnk · · 1 min read
1,256 2
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 :(

Discussion

Loading comments...