Constructors for Composed Objects
Hi there
This is my first cpp program, so please be patient with me...
I am trying to practice applying constructors on a composed class, and have learned that in case of a composed class, the outer class ctor is responsible for initialaizing the inner class, and this can be achieved by using an initialization list.
So here's my code:
class Point
{
private:
int x;
int y;
};
class Rectangle
{
public:
Rectangle(int px, int py, int width, int height);
height);
private:
Point x;
Point y;
int m_width;
int m_height;
};
and heres my ctor :
Rectangle::Rectangle(int px,int py,int width,int height)
:x(px),y(py),m_width(width),m_height(height)
{}
Still, I get a compiler error C2664: '__thiscall Point::Point(const class Point &)' : cannot convert parameter 1 from 'int' to 'const class Point &'
Reason: cannot convert from 'int' to 'const class Point'
No constructor could take the source type, or constructor overload resolution was ambiguous
I understand the meaning of this error, but isnt this what init. list are for?
Please help!
Thanks
Gozlan