1

Suppose I have the following:

template<typename T>
    struct Foo
    {
    public:
        class Bar
        {           
        };
    };

If I then define the function

template <typename T>
void func(Foo<T>::Bar g) { }

I get an error: syntax error: identifier 'Bar'

Why do I get the error and how can I solve it so that I can use the templated function.

SilverTear
  • 695
  • 7
  • 18

1 Answers1

0

Use

template <typename T>
void func( typename Foo<T>::Bar g ) { }

Otherwise the construction Foo<T>::Bar is not considered by the compiler as a type specifier but as an expression.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335