这是我的问题 - 执行此代码后将创建多少个对象?
class vehicle
{ public:
int Weight, HorsePower;
vehicle(int x, int y)
{ Weight = x;
HorsePower = y;
}
};
class car : public vehicle
{ public:
car(int x, int y) : vehicle(x, y)
{ }
};
class motorcycle : private vehicle
{ public:
motorcycle(int x, int y):
{ Weight = x;
HorsePower = y;
}
};
int _tmain(int argc, _TCHAR* argv[])
{ car Ferrari(4056,540);
motorcycle Suzuki(429,103);
return 0;
}
我和我的朋友争论的是我的观点是 4 个对象——汽车、摩托车和 2 个车辆,因为每个对象都派生出车辆。这是真的?