forward declaration of a template class?

Discussion in 'C++' started by Nobody, Feb 12, 2004.

  1. Nobody

    Nobody Guest

    what is the syntax for a forward declaration of a template class?


    normally I declare all my classes at the top of the header:

    class CClass1;
    class CClass2;

    class CClass1 : public CBase
    {
    };

    class CClass2 : public CBase
    {
    }

    this doesn't seem to work with a template class? I get all sorts of errors.
     
    Nobody, Feb 12, 2004
    #1
    1. Advertising

  2. "Nobody" <> wrote in message
    news:%lFWb.28941$1O.21160@fed1read05...
    > what is the syntax for a forward declaration of a template class?
    >
    >
    > normally I declare all my classes at the top of the header:
    >
    > class CClass1;
    > class CClass2;
    >
    > class CClass1 : public CBase
    > {
    > };
    >
    > class CClass2 : public CBase
    > {
    > }
    >
    > this doesn't seem to work with a template class? I get all sorts of

    errors.
    >



    template <class T>
    class X;

    is perfectly good template class forward declaration.

    If that doesn't help then perhaps you should post the code you are actually
    having trouble with. And mention the compiler since many compilers have a
    few quirks when it comes to templates.

    john
     
    John Harrison, Feb 12, 2004
    #2
    1. Advertising

  3. Nobody

    Nobody Guest

    Ooops... I figured it out. I was using a default param in the template. I
    had to remove that from the definition and only use it in the forward
    declaration.

    "John Harrison" <> wrote in message
    news:c0f8au$16ncku$-berlin.de...
    >
    > "Nobody" <> wrote in message
    > news:%lFWb.28941$1O.21160@fed1read05...
    > > what is the syntax for a forward declaration of a template class?
    > >
    > >
    > > normally I declare all my classes at the top of the header:
    > >
    > > class CClass1;
    > > class CClass2;
    > >
    > > class CClass1 : public CBase
    > > {
    > > };
    > >
    > > class CClass2 : public CBase
    > > {
    > > }
    > >
    > > this doesn't seem to work with a template class? I get all sorts of

    > errors.
    > >

    >
    >
    > template <class T>
    > class X;
    >
    > is perfectly good template class forward declaration.
    >
    > If that doesn't help then perhaps you should post the code you are

    actually
    > having trouble with. And mention the compiler since many compilers have a
    > few quirks when it comes to templates.
    >
    > john
    >
    >
     
    Nobody, Feb 12, 2004
    #3
    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. jobseeker
    Replies:
    2
    Views:
    1,121
    DarkSpy
    Oct 15, 2003
  2. qazmlp
    Replies:
    1
    Views:
    624
    Jonathan Turkanis
    Feb 15, 2004
  3. verec
    Replies:
    2
    Views:
    1,075
    verec
    Jun 25, 2005
  4. steprobe
    Replies:
    3
    Views:
    509
    Vladimir Jovic
    Apr 7, 2010
  5. Jure Erznožnik

    Forward template declaration problem

    Jure Erznožnik, Mar 12, 2011, in forum: C++
    Replies:
    4
    Views:
    768
    Jure Erznožnik
    Mar 12, 2011
Loading...

Share This Page