标题:一个新建类,运用构造以及拷贝函数的小例子求解
只看楼主
皎皎明月
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-4-28
结帖率:0
已结贴  问题点数:20 回复次数:1 
一个新建类,运用构造以及拷贝函数的小例子求解
//全部代码如下//
#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
^^^^^^
不知道是怎么回事的说。。。。。
搜索更多相关主题的帖子: include public number 新建 
2014-04-28 23:32
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:20 
你的问题很多

回正题,最主要的是 class Car {……} 后面缺了分号,即 class Car {……};
2014-04-29 10:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-430792-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.288740 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved