开发者

GCC problem: in template

开发者 https://www.devze.com 2022-12-22 21:35 出处:网络
i have redhat with gcc 4.1.1 i have compile as \"gcc test.c\" and give the following error Error : expected \'=\' ,\',\' , \';\' , ásm\' or \'__ attribute__\' before \'<\' token

i have redhat with gcc 4.1.1 i have compile as "gcc test.c" and give the following error

Error : expected '=' ,',' , ';' , ásm' or '__ attribute__' before '<' token

the code in "test.c" is as follow

开发者_开发问答
template <typename T> class A {
public:
    T foo;
};


Compile with g++ and/or rename your file to test.cpp.

If you compile with gcc test.c then your file will be assumed as a C file. There's no templates in C.


This is C++ code, not C. You need to use g++, i.e. g++ test.c. Also, to avoid confusion, you should rename your file to end with .cpp or .cxx.


From the GCC Manual, compiling a file with the .c extension will compile your code as though it were C, not C++. The easiest solution is to compile your code with g++ instead. The g++ command sets the default language to C++ and automatically links your code against the C++ standard library. You can do both of those with gcc but you have to do it by hand. Exactly how you do that is left as an exercise. :-)

0

精彩评论

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

关注公众号