一个新建类,运用构造以及拷贝函数的小例子求解
//全部代码如下//#include <iostream>
using namespace std;
class Car
{
public:
int m_nNumber;
char m_strPinpai[20];
int m_nYouliang;
int m_nLicheng;
int m_nYouhao;
Car(int number,char pinpai,int youliang,int licheng,int youhao)
{
m_nNumber=number;
m_strPinpai[20]=pinpai;
m_nYouliang=youliang;
m_nLicheng=licheng;
m_nYouhao=youhao;
}
Car(Car&car1);
~Car()
{
cout<<"xigou is called!"<<endl;
}
}
Car::Car(Car&car1)
{
m_nNumber=car1.m_nNumber;
m_strPinpai[20]=car1.m_strPinpai[20];
m_nYouliang=car1.m_nYouliang;
m_nLicheng=car1.m_nLicheng;
m_nYouhao=car1.m_nYouhao;
cout<<"kaobeigouzao is called!"<<endl;
};
void fun1(Car car1)
{
cout<<"car1 is:"<<570<<""<<'hongqi'<<""<<80<<""<<5000<<""<<3720<<endl;
}
Car fun2()
{
Car car2('571','fengtian','81','5100','3721');
return car2;
}
int main()
{
cout << "Hello world!" << endl;
return 0;
Car car2('572','baoma','82','5200','3722');
Car car3(car2);
cout<<"car3 is:"<<m_nNumber()<<""<<m_strPinpai[20]<<""<<m_nYouliang<<""<<m_nLicheng<<""<<m_nYouhao<<endl;
fun1(Car car3);
cout<<"car3 is:"<<m_nNumber()<<""<<m_strPinpai[20]<<""<<m_nYouliang<<""<<m_nLicheng<<""<<m_nYouhao<<endl;
car3=fun2();
cout<<"car3 is:"<<m_nNumber()<<""<<m_strPinpai[20]<<""<<m_nYouliang<<""<<m_nLicheng<<""<<m_nYouhao<<endl;
}
个人感觉没什么问题,但是总是报错,错误如下:
return type specification for constructor invalid
m_nNumber was not declared in this scope
^^^^^^
不知道是怎么回事的说。。。。。