我正在考完我的舊考試去學習決賽,並且注意到了一些我仍然不明白的東西。派生類中的默認構造函數
class Shape
{
private:
int center_x, int center_y;
public:
Shape (int x, int y) : center_x(x), center_y(y); {} //constructor initializer
}
class Rectangle : public Shape
{
private:
int length, width;
public:
Rectangle(): //this is where i have trouble, I am supposed to fill in missing code here
//but shape does not have a default constructor, what am i supposed to fill in here?
Rectangle (int x, int y, int l, int w) : Shape(x,y);{length = l; width = w;}
}
感謝
你能澄清你的問題嗎?位? –
對不起,我應該給給定的構造函數添加定義,當他們給我Rectangle()時,我不知道在冒號後面填充什麼。 – ricefieldboy
密切相關:http://stackoverflow.com/q/1711990/179910 –