Class template syntax

Discussion in 'C++' started by Matthias =?ISO-8859-1?Q?K=E4ppler?=, Dec 1, 2004.

  1. 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
    Matthias =?ISO-8859-1?Q?K=E4ppler?=, Dec 1, 2004
    #1
    1. Advertising

  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;
    > };
    >
    > 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.
    Matthias =?ISO-8859-1?Q?K=E4ppler?=, Dec 1, 2004
    #2
    1. Advertising

  3. Matthias =?ISO-8859-1?Q?K=E4ppler?=

    Sumit Rajan Guest

    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, Dec 2, 2004
    #3
  4. 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.
    Matthias =?ISO-8859-1?Q?K=E4ppler?=, Dec 2, 2004
    #4
  5. Matthias =?ISO-8859-1?Q?K=E4ppler?=

    Sumit Rajan Guest

    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, Dec 2, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BigMan
    Replies:
    1
    Views:
    521
  2. christopher diggins
    Replies:
    16
    Views:
    735
    Pete Becker
    May 4, 2005
  3. toton
    Replies:
    1
    Views:
    607
  4. Replies:
    1
    Views:
    2,088
    Gianni Mariani
    Jun 8, 2007
  5. A L
    Replies:
    1
    Views:
    504
    Alf P. Steinbach /Usenet
    Aug 25, 2010
Loading...

Share This Page