1 c++ class declaration definition
我没有使用搜索找到我的问题的答案,但我认为这很简单而且很受欢迎.无论如何,我的问题是:我有一个头文件,它声明了一个类和函数.它看起来像这样:
#ifndef SOME_CLASS_H
#define SOME_CLASS_H
#include <string>
class mySomeClass
{
public:
bool a_func(string & myString, unsigned long int & x);
void b_func(string & myString, unsigned long int & x);
void c_func(string & myString, unsigned long int & x);
void another_func(string & myString, string & myString2);
}
#endif // SOME_CLASS_H
Run Code Online (Sandbox Code Playgroud)
我认为功能定义现在并不重要.
在编译时,编译器告诉'string'尚未声明,即使我已经添加了#include <string>.除了重写要使用的函数之外,我该如何解决这个问题char*.先感谢您.
完成.谢谢大家.
Gre*_*g S 10
问题:string类位于命名空间中std.
解决方案:
std::string而不是
string在函数声明中.using namespace std;在include指令后添加(有关缺点/危险的解释using,请参阅sbi注释中的链接).string在命名空间中声明std,因此您必须将函数声明更改为
bool a_func(std::string & myString, unsigned long int & x);
Run Code Online (Sandbox Code Playgroud)