输出有误!请大神指教!!!
#include<iostream>using namespace std;
class car
{
private:
char * brand,* type,* year;
int price;
public:
car(char * brand,char * type,char * year,int price);
~car();
void pout();
};
int main()
{
char * brand,char * type,char * year,int x;
brand="宝马";
type="Q5";
year="2005年九月份";
x=4000000;
cout<<" 这是书上第三章116页第3题的参考答案!"<<endl<<endl;
system("color 3e");
car p1(brand,type,year,x);
p1.pout();
return 0;
}
car::car(char * brand,char * type,char * year,int price)
{
this->brand=new char[strlen(brand)+1];
strcpy(this->brand,brand);
this->type=new char[strlen(year)+1];
strcpy(this->type,type);
this->year=new char[strlen(year)+1];
strcpy(this->year,year);
this->price=price;
}
car::~car()
{
delete []brand;
delete []type;
delete []year;
}
void car::pout()
{
cout<<"品牌:"<<brand<<" 型号:"<<type<<" 生产年份:"<<year<<" 价格:"<<price<<endl<<endl;
}
为什么输出的价格不是4000000而是0???求大神指教呀!