C ++ passes internal structure as parameter

There is a structure containing the internal structure of TIn:

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

    TIn in;
T t;
};

How to pass TIn 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
+5
source share
2 answers

You need to use the keyword typename:

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

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

+7
source

Why can't you use simpler

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

instead

+2
source

All Articles