开发者

Error when using `link` as a class name in C++

Consider a simple program in C++:

#include <开发者_JAVA百科;iostream>

class link {};

int main() {
    link alink;
}

Compiling it with g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2 gives the following error:

test.cpp:6:8: error: expected ‘;’ before ‘alink’

Why do I get this error?


Because link is also a posix function and the function name hides the class name.

You can say class link alink; but better put your class into a new namespace or rename it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜