我不知道我是否应该创建一个析构函数来删除Controller
设置为由 main 传递的参数的成员,这些参数是动态创建的,因为构造函数从未使用new
关键字来设置它们。
int main()
{
int numCars = 3;
int numPlanes = 3;
Machine *car= new Car[numCars];
Machine *plane = new Plane[numPlanes];
Controller *control = new Controller(car, plane);
delete control;
return 0;
}
class Controller
{
public:
Controller(Machine *car, Machine *plane);
//Would I need to make a destructor
//~Controller();
private:
Machine *car;
Machine *plane;
Controller :: Controller(Machine *car, Machine *plane)
{
this->car = car;
this->plane = plane;
changeCarandPlane();
}
//destructor
// Controller :: ~Controller()
// {
// delete[] car;
// delete[] plane;
// }
};