ABu
ABu

Reputation: 12249

Something unrecognize in template function working with a template object

Gcc (4.7.2) throws a little error compiling this code:

#include <iostream>

template<typename T>
struct test
{
    template<int n>
    int select() const
    {
        return n;
    }
};

template<typename T>
struct test_wrapper
{
    void print() const
    {
        std::cout << t.select<3>() << std::endl; // L.18
    }

    test<T> t;
};

int main()
{}

And the error is:

test3.cpp: In member function 'void test_wrapper<T>::print() const':
test3.cpp:18:34: error: expected primary-expression before ')' token

If I change test<T> t by a specialized type, for example test<void> t, this error dissapear.

Where is the problem?

Upvotes: 0

Views: 49

Answers (1)

David G
David G

Reputation: 96790

You need to use the template keyword when calling a template method inside a templated construct:

t.template select<3>();

Upvotes: 7

Related Questions