M
Makis Papapanagiotou
Hello all,
There is a strange case where a class Test is composed from three objects of
other classes. i.e.
class Test
{ public:
Test();
private:
Point x;
Cat y;
Dog z;
};
where the classes Point, Cat, Dog are
class Point
{ public:
Point();
Point(Point& x, Dog& y);
private:
};
class Cat
{ public:
Cat();
Cat(Point& x, Dog& y);
private:
};
class Dog
{ public:
Dog();
Dog(Point& x, Cat& y);
private:
};
If we were calling the default constructors they is no problem, since as
STROUSTRUP is wrtiing in his book they are called in the order they are
defined in the class the main class (Test).
My big problem is why the following is working? i.e when the other
constructors are called.
Test::Test():x(), y(x,z), z(x,y)
since the creation of object "y" is related with the creation of object "z".
Can any body give an explanation of this strange behaviour?
Thanks in advance,
There is a strange case where a class Test is composed from three objects of
other classes. i.e.
class Test
{ public:
Test();
private:
Point x;
Cat y;
Dog z;
};
where the classes Point, Cat, Dog are
class Point
{ public:
Point();
Point(Point& x, Dog& y);
private:
};
class Cat
{ public:
Cat();
Cat(Point& x, Dog& y);
private:
};
class Dog
{ public:
Dog();
Dog(Point& x, Cat& y);
private:
};
If we were calling the default constructors they is no problem, since as
STROUSTRUP is wrtiing in his book they are called in the order they are
defined in the class the main class (Test).
My big problem is why the following is working? i.e when the other
constructors are called.
Test::Test():x(), y(x,z), z(x,y)
since the creation of object "y" is related with the creation of object "z".
Can any body give an explanation of this strange behaviour?
Thanks in advance,