Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Class template syntax

Reply
Thread Tools

Class template syntax

 
 
Matthias =?ISO-8859-1?Q?K=E4ppler?=
Guest
Posts: n/a
 
      12-01-2004
Hi,

in Nicolai Josuttis book about the C++ standard library, class templates are
defined like this:

template<class T>
class MyClass<T>
{
T value;
};

That doesn't work for me (g++ 3.3.4):
templates.cpp:4: error: `MyClass' is not a template
templates.cpp:6: confused by earlier errors, bailing out

I have always used this syntax:

template<class T> // or preferrably 'typename T'
class MyClass // no <T> here
{
T value;
};

Which has always worked for me. I am just curious why the syntax presented
in one of the (if not *the*) most popular books about the C++ standard
library doesn't compile with g++ (which is probably as popular as the book
*g*).

Thanks,
Matthias
 
Reply With Quote
 
 
 
 
Matthias =?ISO-8859-1?Q?K=E4ppler?=
Guest
Posts: n/a
 
      12-01-2004
Matthias Käppler wrote:

> Hi,
>
> in Nicolai Josuttis book about the C++ standard library, class templates
> are defined like this:
>
> template<class T>
> class MyClass<T>
> {
> T value;
> };
>
> That doesn't work for me (g++ 3.3.4):
> templates.cpp:4: error: `MyClass' is not a template
> templates.cpp:6: confused by earlier errors, bailing out
>
> I have always used this syntax:
>
> template<class T> // or preferrably 'typename T'
> class MyClass // no <T> here
> {
> T value;
> };
>
> Which has always worked for me. I am just curious why the syntax presented
> in one of the (if not *the*) most popular books about the C++ standard
> library doesn't compile with g++ (which is probably as popular as the book
> *g*).
>
> Thanks,
> Matthias


I just looked at another example, where he didn't notate the <T>. Maybe that
was just a typo...? Whatever.
 
Reply With Quote
 
 
 
 
Sumit Rajan
Guest
Posts: n/a
 
      12-02-2004
Matthias Käppler wrote:
> Hi,
>
> in Nicolai Josuttis book about the C++ standard library, class templates are
> defined like this:
>
> template<class T>
> class MyClass<T>
> {
> T value;
> };


Where exactly in the book did you come across this one?
--
Sumit Rajan <(E-Mail Removed)>
 
Reply With Quote
 
Matthias =?ISO-8859-1?Q?K=E4ppler?=
Guest
Posts: n/a
 
      12-02-2004
Sumit Rajan wrote:

> Matthias Käppler wrote:
>> Hi,
>>
>> in Nicolai Josuttis book about the C++ standard library, class templates
>> are defined like this:
>>
>> template<class T>
>> class MyClass<T>
>> {
>> T value;
>> };

>
> Where exactly in the book did you come across this one?


Don't have it at hand right now, but it was in the very first chapter I
think. But nevermind, it probably was just a typo, since the other examples
were fine.
 
Reply With Quote
 
Sumit Rajan
Guest
Posts: n/a
 
      12-02-2004
Matthias Käppler wrote:

> Don't have it at hand right now, but it was in the very first chapter I
> think. But nevermind, it probably was just a typo, since the other examples
> were fine.



You are right. There is a typo in Section 2.2.1 (Page 12 and 13). This
is what the author's website has to say about it:



Page 12 and 13, Section 2.2.1
On both pages replace:
template <class T>
class MyClass<T> {
by:
template <class T>
class MyClass {


Regards,
Sumit.
--
Sumit Rajan <(E-Mail Removed)>
 
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
Declaring a template class with two template params a friend in anon-template class A L C++ 1 08-25-2010 07:25 AM
template template arguments: expected a class template, got `Component<T1, T2, T3> gary.bernstein@gmail.com C++ 1 06-08-2007 07:10 AM
syntax problem for partial template specialization for a template class. toton C++ 1 12-28-2006 04:08 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
Out-of-class-template member template specialization syntax BigMan C++ 1 03-26-2005 02:23 PM



Advertisments