Templated class declaration - c++

This is a discussion on Templated class declaration - c++ ; Hi, With a normal class, I can do the following: --- class Foo; void func( Foo* param ); class Foo { //defined here }; --- How do I declare a templated class before the actual definition? --- class WStr; // ...

+ Reply to Thread
Results 1 to 2 of 2

Templated class declaration

  1. Default Templated class declaration

    Hi,

    With a normal class, I can do the following:

    ---
    class Foo;

    void func( Foo* param );

    class Foo
    {
    //defined here
    };
    ---


    How do I declare a templated class before the actual definition?

    ---
    class WStr; // Does not work, the compiler complains about
    redifinition.

    void func( WStr* param );

    template< class T >
    class Tmpl
    {
    //defined here
    T* t;
    };

    typedef Tmpl< char > WStr;
    ---


    Thank you,

    Steve


  2. Default Re: Templated class declaration

    Steve: wrote:
    > Hi,
    >
    > With a normal class, I can do the following:
    >
    > ---
    > class Foo;
    >
    > void func( Foo* param );
    >
    > class Foo
    > {
    > //defined here
    > };
    > ---
    >
    >
    > How do I declare a templated class before the actual definition?
    >
    > ---
    > class WStr; // Does not work, the compiler complains about
    > redifinition.


    template<class T> class Tmpl;

    >
    > void func( WStr* param );


    If this is a concrete function (with a certain template specialisation
    as the argument type), then do

    void func( Tmpl<char>* param );

    If it does not work for you, maybe you can put the declaration after
    the definition of 'Tmpl' class.

    >
    > template< class T >
    > class Tmpl
    > {
    > //defined here
    > T* t;
    > };
    >
    > typedef Tmpl< char > WStr;
    > ---


    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask



+ Reply to Thread

Similar Threads

  1. class declaration versus class header #include
    By Application Development in forum c++
    Replies: 9
    Last Post: 12-07-2007, 12:28 PM
  2. Array of Base Class Pointers (Templated)
    By Application Development in forum c++
    Replies: 3
    Last Post: 12-05-2007, 12:25 AM
  3. Defining a cast on a templated class
    By Application Development in forum c++
    Replies: 14
    Last Post: 11-15-2007, 04:46 AM
  4. how to define const double in a templated class
    By Application Development in forum c++
    Replies: 1
    Last Post: 09-29-2007, 09:49 AM