在我的Function.h文件中:
class Function{
public:
Function();
int help();
};
Run Code Online (Sandbox Code Playgroud)
在我的Function.cpp文件中:
#include "Function.h"
int Function::help() //Error here
{
using namespace std;
cout << "Help";
return 1;
}
Run Code Online (Sandbox Code Playgroud)
在我的Main.cpp中
#include <iostream>
#include "Function.h"
using namespace std;
int menu(){
Function fc;
fc.help();
return 1;
}
int main(int args, char**argv){
return menu();
}
Run Code Online (Sandbox Code Playgroud)
错误是:'函数'尚未声明
可以有人告诉我为什么?谢谢.
我试过这样,问题解决了,但我真的不明白为什么:
在Function.h文件中:
我用
class Function{
public:
int status;
Function():status(1){}
int help();
};
Run Code Online (Sandbox Code Playgroud)
而不是旧的
class Function{
public:
Function();
int help();
};
Run Code Online (Sandbox Code Playgroud)
您的所有include语句都缺少#:
#include "Function.h"
^
Run Code Online (Sandbox Code Playgroud)
其他一切看起来都很好,但是你需要#include <iostream>在Function.cpp中使用它cout.
这是我编译和运行的Function.cpp:
#include "Function.h"
#include <iostream>
int Function::help() // No error here
{
using namespace std;
cout << "Help";
return 1;
}
Function::Function()
{
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26346 次 |
| 最近记录: |