help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Learning templates


From: ArbolOne
Subject: Learning templates
Date: Sun, 9 Sep 2012 14:29:20 -0700 (PDT)
User-agent: G2/1.0

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?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]