简单c++问题,关于自定义头和相关编译问题.50分

pqzha1 pqzha1 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我定义3个文件,plane.h, plane.cpp. app.cpp (app.cpp是主程序)

--------------------plane.h---------------------------
#ifndef PLANE_H
#define PLANE_H


class Plane
{
private:
int ticketNum;

public:
Plane (int);
int getNum(void);
void setNum(int);
};


#endif
--------------------plane.cpp------------------------------------
#include <iostream>
#include "plane.h"
using namespace std;

Plane::Plane(int num)
{
ticketNum = num;

}


int Plane::getNum()
{
return ticketNum;
}


void Plane::setNum(int num)
{
ticketNum = num;
}
------------------app.cpp---------------------------------
#include "plane.h"
#include <iostream>

using namespace std;

int main()
{
Plane a(5);
cout<<a.getNum()<<endl;


}
-------------------------------------
我用这个命令去编译(不确定对不对)

g++ app.cpp plane.cpp -o app

但是,错误发生,结果如下:

[root@localhost assignment]# g++ app.cpp plane.cpp -o app
app.cpp: In function `int main()':
app.cpp:9: error: 'class Plane' has no member named 'getNum'

我不知道为什么说plane类里没有成员函数getNum.我定义了啊~ 
解决转200卡..
...全文

相关推荐

评论 18
收藏 已收藏
分享
返回顶部
pqzha1
C++ 语言 65,214 成员 250,514 内容