2

The following code compiles fine under Visual C++ 2010, but not under GCC 4.6 from the Android NDK r8b.

template<typename A>
struct foo
{
    template<typename B>
    B method()
    {
        return B();
    }
};

template<typename A>
struct bar
{
    bar()
    {
        f_.method<int>(); // error here
    }

private:
    foo<A> f_;
};

The error GCC gives is

error : expected primary-expression before 'int'
error : expected ';' before 'int'

for the marked line. For the life of me I can't figure out whats wrong.

Eoin
  • 1,709
  • 11
  • 22
  • 1
    duplicated from http://stackoverflow.com/questions/1840253/c-template-member-function-of-template-class-called-from-template-function – Ninten Sep 27 '12 at 20:08

1 Answers1

8

GCC is correct, since f_ is of type foo<A> which depends on the template parameter A, you need to qualify the call to method with the template keyword:

f_.template method<int>();  // This will work
Seg Fault
  • 1,331
  • 8
  • 16