| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Matthias =?ISO-8859-1?Q?K=E4ppler?=" |
| Date: |
01 Dec 2004 03:26:52 PM |
| Object: |
Class template syntax |
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
.
|
|
| User: "Matthias =?ISO-8859-1?Q?K=E4ppler?=" |
|
| Title: Re: Class template syntax |
01 Dec 2004 03:30:23 PM |
|
|
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.
.
|
|
|
|
| User: "Sumit Rajan" |
|
| Title: Re: Class template syntax |
01 Dec 2004 09:08:39 PM |
|
|
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 <sumit.rajan@gmail.com>
.
|
|
|
| User: "Matthias =?ISO-8859-1?Q?K=E4ppler?=" |
|
| Title: Re: Class template syntax |
02 Dec 2004 02:14:48 AM |
|
|
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.
.
|
|
|
| User: "Sumit Rajan" |
|
| Title: Re: Class template syntax |
02 Dec 2004 03:36:18 AM |
|
|
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 <sumit.rajan@gmail.com>
.
|
|
|
|
|
|

|
Related Articles |
|
|