A
ArbolOne
MinGW - GNU c++
main.cpp
~~~~~~~~
template <typedef T>
class List{
private:
size_t id;
T data;
public:
T& getData(){ return T;}
int getId(){return id;}
void setData(T const & d){data = d;}
void setId(const int i){ id = i;}
}
int main(){
return 0;
}
I am learing how to use c++ templates, but this simple example gives me the following error:
....\Templates\main.cpp:1:19: error: 'T' does not name a type
....\Templates\main.cpp:12:1: error: ISO C++ forbids declaration of 'parameter' with no type [-fpermissive]
....\Templates\main.cpp:12:1: error: typedef declaration invalid in parameter declaration
....\Templates\main.cpp:13:1: error: expected '>' before 'int'
....\Templates\main.cpp:13:11: error: expected unqualified-id before '{' token
Process terminated with status 1 (0 minutes, 0 seconds)
5 errors, 0 warnings
AFAIK g++ supports templates, so there must be something wrong with the code, any body?
main.cpp
~~~~~~~~
template <typedef T>
class List{
private:
size_t id;
T data;
public:
T& getData(){ return T;}
int getId(){return id;}
void setData(T const & d){data = d;}
void setId(const int i){ id = i;}
}
int main(){
return 0;
}
I am learing how to use c++ templates, but this simple example gives me the following error:
....\Templates\main.cpp:1:19: error: 'T' does not name a type
....\Templates\main.cpp:12:1: error: ISO C++ forbids declaration of 'parameter' with no type [-fpermissive]
....\Templates\main.cpp:12:1: error: typedef declaration invalid in parameter declaration
....\Templates\main.cpp:13:1: error: expected '>' before 'int'
....\Templates\main.cpp:13:11: error: expected unqualified-id before '{' token
Process terminated with status 1 (0 minutes, 0 seconds)
5 errors, 0 warnings
AFAIK g++ supports templates, so there must be something wrong with the code, any body?