简单c++问题,关于自定义头和相关编译问题.50分
我定义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卡..