473,395 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
Jul 22 '05 #1
4 1152
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.
Jul 22 '05 #2
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 <su*********@gmail.com>
Jul 22 '05 #3
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.
Jul 22 '05 #4
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 <su*********@gmail.com>
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
7
by: Thomas Matthews | last post by:
Hi, I am converting my table and record classes into templates. My issue is the syntax of declaring a friend class within the template. I have searched the C++ FAQ Lite (web), the C++...
5
by: rich | last post by:
Hi there, I defined a class template (MyClass) and some member variables and functions, as following: template<class T1, class T2> class MyClass { ... struct m_variable
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
4
by: Joseph Turian | last post by:
Hi, What is the correct syntax to get the bar<T>::f<int, unsigned>() function to compile in the following fragment? Thanks, Joseph class foo {
4
by: Gary li | last post by:
Hi, all I find "template template" class cann't been compiled in VC6 but can ok in Redhat9. I write a test program like as: template< template<class> class T> class A { }; int main() {...
1
by: toton | last post by:
Hi, I am doing some template specialization for a template class, where specialization is done on a member function. I am not able to get exact syntax for it. The code is give as below, enum...
5
by: Marcin Gil | last post by:
Hi! I have the code like this (obvious things like ctor/dtor removed) typedef struct _NODE { int val; int index; } Node;
3
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: ...
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.