怎么给C++对象斌空

来源:百度知道 编辑:UC知道 时间:2024/05/27 22:07:35
我在斌空时报错 Vehicle vehicle=null;

#pragma once
#include "Vehicle.h"
#include "Truck.h"
#include "Car.h"
ref class VehicleFactory
{
public:
VehicleFactory(void);
public : Vehicle CreateVehicle(String^ licenseNo,String^ name,String^ Color,int YearsOfService,double dalRyent,int load,int type)
{
Vehicle vehicle=null;
switch (type)
{
case 1:
vehicle = gcnew Car(licenseNo, name, Color, YearsOfService, dalRyent);
break;
case 2:
vehicle = gcnew Truck(licenseNo, name, Color, YearsOfService, dalRyent, load);
break;
}
return vehicle;
}
};

要先 #include 宏 null 或 宏 NULL 所在的头文件。
或者自己定义 宏 null

对象不能赋NULL的。 你想下, 你自定义的一个对象可以等于0(NULL)吗, 如果等于0, 是他的哪个属性等于0?