0

I don't understand why the following code doesn't compile:

template< typename TypeArg >
class Data
{
public:
    struct Selector1
    {
    };

    template< typename Selector >
    void foo()
    {
    }
};

template< typename TypeArg >
class Test
{
public:
    void test();
};


template< typename TypeArg >
void Test< TypeArg >::test()
{
    Data< TypeArg > data;
    data.foo< typename Data< TypeArg >::Selector1 >();
}

I have tested it with GCC 4.6 and GCC 4.9. Both give me the same error:

test.cpp: In member function »void Test::test()«: test.cpp:28:51: Error: expected »(« before »>« token test.cpp:28:53: Error: expected primary-expression before »)« token

Can somebody tell me what needs to be done for the code to compile?

theV0ID
  • 3,983
  • 9
  • 33
  • 55

1 Answers1

5

Since the type of data is dependent, the nature of data.foo is not known and needs to be disambiguated:

data.template foo<typename Data< TypeArg >::Selector1>();
//   ^^^^^^^^
Kerrek SB
  • 447,451
  • 88
  • 851
  • 1,056