5

There is a structure TOut containing inner structure TIn:

template <typename T>
struct TOut
{
    struct TIn
    {
            bool b;
    };

    TIn in;
T t;
};

How to correctly pass TIn in as a formal parameter of some method?

class Test
{
public:
    template <typename T>
    static void test ( const TOut<T>::TIn &i) {} //Error
};


int main()
{
TOut <double> o;
Test::test(o.in);
}

The program compiles with the following error:

Error   4   error C2998: 'int test' : cannot be a template definition
justik
  • 4,145
  • 6
  • 32
  • 53
  • http://stackoverflow.com/questions/7178948/problem-with-functions-accepting-inner-classes-of-template-classes – Lol4t0 Jan 25 '12 at 20:24
  • @TJD `Tin` would be a known ("concrete") type if it where declared beside `Tout`, or inside a non-template class. At the point where the OP is getting an error, `Tin` is not yet known, because `TOut` is not yet instantiated. BTW, the term "concrete" is normally used in the context of inheritance (opposite of "abstract"). – Emile Cormier Jan 25 '12 at 20:38

2 Answers2

7

You need to use the typename keyword:

template <typename T>
static void test ( const typename TOut<T>::TIn &i) {}

See Where and why do I have to put the "template" and "typename" keywords?

Community
  • 1
  • 1
Emile Cormier
  • 28,391
  • 15
  • 94
  • 122
2

Why cannot you use the simpler

template <typename T>
static void test (const T& i)

instead?

6502
  • 112,025
  • 15
  • 165
  • 265