-
Initializer list order is restricted by the order of data member declarations in
your class!
-
Because constructor call order is *very* important, modern compilers will
generate errors when initializer list does not follow the order of class data members!
|
// point.h
class Graph { /*...*/ };
class Point {
private:
Graph& m_g;
int m_x;
int m_y;
public:
Point( Graph& g, int x, int y );
};
// point.cpp
Point::Point( Graph& g, int x, int y )
:
m_x( x ),
m_y( y ),
m_g( g ) // out of order
{
}
// main.cpp
void main()
{
Graph gr;
Point pt( gr, 10, 20 );
}
|