开发者

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

开发者 https://www.devze.com 2023-04-11 23:03 出处:网络
Consider a simple program in C++: #include <开发者_JAVA百科;iostream> class link {}; int main() {

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

精彩评论

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