【发布时间】:2010-12-13 12:02:52
【问题描述】:
我有一个包含一组函数的文件。对于其中一个函数,我想编写一个辅助函数,它基本上采用 char * 并跳过所有空格。
我认为应该这样做:
namespace {
const int kNotFound = -1;
void SkipWhitespace(const char *s); // forward declaration - doesn't seem to work?
}
void foo(const char *s1, const char *s2) {
// do some stuff
SkipWhitespace(s1);
SkipWhitespace(s2);
// continue with other stuff
}
void SkipWhitespace(const char *s) {
for (; !isspace(s); ++s) {}
}
但这给了我一个编译器错误。我需要将定义放在未命名的命名空间中吗?
【问题讨论】:
-
您在列表中写下了 const char s*。这是不对的。 -> 字符 *s
-
您还需要创建函数 'void SkipWhitespace(const char*&s)'
-
由于 SkipWhitespace 定义中的拼写错误,您遇到了错误。应该是 void SkipWhitespace(const char *s)
-
只是发布源中的一个错字。
-
是的。您希望“SkipWhiteSpace”返回调整过空格的指针。
标签: c++ namespaces