tags:

views:

77

answers:

3

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;
};
+5  A: 

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.

KennyTM
+1  A: 

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.

Håvard S
+1  A: 

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. :-)

Kristo