Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Templates and g++

Reply
Thread Tools

Templates and g++

 
 
ArbolOne
Guest
Posts: n/a
 
      09-09-2012
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 With Quote
 
 
 
 
Dombo
Guest
Posts: n/a
 
      09-09-2012
Op 09-Sep-12 23:30, ArbolOne schreef:
> MinGW - GNU c++
> main.cpp
> ~~~~~~~~
> template <typedef T>

^^^^^^^

Use typename or class here.

 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      09-09-2012
ArbolOne wrote:

> MinGW - GNU c++
> main.cpp
> ~~~~~~~~
> template <typedef T>


What is "typedef" doing there? Did you mean "class" or "typename"?

> 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;}
> }


Missing ';'.

> 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


Yes, g++ agrees with me.

> ...\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

 
Reply With Quote
 
Luca Risolia
Guest
Posts: n/a
 
      09-09-2012
On 09/09/2012 23:35, Marc wrote:
> ArbolOne wrote:
>> template <typedef T>

>
> What is "typedef" doing there? Did you mean "class" or "typename"?
>
>> class List{
>> T& getData(){ return T;}


...and the above line is wrong as well: it's probably
T& getData(){ return data;}

>> }

>
> Missing ';'.



 
Reply With Quote
 
ArbolOne
Guest
Posts: n/a
 
      09-09-2012
Thanks folks, I got it now.


On Sunday, September 9, 2012 5:30:01 PM UTC-4, ArbolOne wrote:
> 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 With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Specializations of function Templates or Overloading Function templates with Templates ? recover C++ 2 07-25-2006 02:55 AM
Monster Templates - Question about Submitting Templates Fred HTML 1 09-26-2005 01:09 AM
Class templates and friend function templates BigMan C++ 1 07-23-2005 09:24 PM
Templates: "implicit typename is deprecated" error and typedef'ing templates Generic Usenet Account C++ 3 07-14-2005 08:02 PM
Templates templates templates JKop C++ 3 07-21-2004 11:44 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57