C++:声明一个带有处理字符串的函数的类
我还没有使用搜索找到我的问题的答案,尽管我认为它简单且流行。无论如何,我的问题是: 我有一个头文件,其中声明了一个类和函数。看起来是这样的:
#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
我认为函数定义现在实际上并不重要。
编译时,编译器告诉 'string' 尚未声明,即使我添加了 #include
。除了重写函数以使用 char* 代替之外,我该如何解决这个问题。先感谢您。
完毕。谢谢大家。
I haven`t found answer to my question using search, though I thought it is simple and popular. Anyway, my question is:
I have got a header file, which declares a class and functions in it. It looks like that:
#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
I think function definitions do not actually matter now.
When compiling, compiler tells that 'string' has not been declared, even though I have added #include <string>
. How can I solve this except for rewriting functions to use char*
instead. Thank you in advance.
Done. Thanks everybody.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
问题:
string
类位于命名空间std
中。解决方案:
std::string
而不是函数声明中的
string
。include 指令(有关
using
的缺点/危险的说明,请参阅 sbi 评论中的链接)。Problem: the
string
class resides in namespacestd
.Solutions:
std::string
instead ofstring
in your function declarations.using namespace std;
after theinclude directive (for an explanation of the drawbacks/dangers of
using
, see the link in sbi's comment).string
是在命名空间std
中声明的,因此您必须将函数声明更改为string
is declared in the namespacestd
, so you have to change the function declarations to您愿意使用的类型
string
是在名为std
的命名空间中声明的。使用 std::string
The type
string
that you're willing to use is declared in a namespace calledstd
.Use
std::string
The type defined in <string> is called std::string, not just string.
放在
下面
put
under