0

look at this sample:

struct parent
{
    template <typename t>
    inline static t get_t();
};

struct child : public parent
{
    template <typename t>
    inline static t get_t()
    {
        return t(-1);
    }
};

template <typename t>
struct call
{
    inline static int get_value()
    {
        return t::get_t<int>();
    }
};

typedef call< child > test;

int main()
{
    int v = test::get_value();
}

The code compile with the following error:

In static member function 'static int call<t>::get_value()':
  error: expected primary-expression before 'int'
  error: expected ';' before 'int'
  error: expected unqualified-id before '>' token

When i compiled the code with visual c++ 2008 and Intel C++ it compiles without problem.

What that error mean?

Muhammad
  • 1,598
  • 3
  • 19
  • 31
  • possible duplicate of [Where and why do I have to put the "template" and "typename" keywords?](http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – Mike Seymour Apr 03 '13 at 16:25

2 Answers2

3

You need the template qualifier:

return t::template get_t<int>();

See:

Where and why do I have to put the "template" and "typename" keywords?

Community
  • 1
  • 1
Pubby
  • 51,882
  • 13
  • 139
  • 180
0

just add

template

keyword:

template <typename t>
struct call
{
    inline static int get_value()
    {
        return t::template get_t<int>();
    }
};
4pie0
  • 29,204
  • 9
  • 82
  • 118