0

The idea is to provide a compile time integer element to a specific function of type S, for different types such as S.

G++ does not allow code below. Who can help me to fix this?

template <class T, int s>
void fn1(T &t)
{
    t.fn2<s>();
}

struct S
{
    template <int s> void fn2 ()
    {
    }
};

void test()
{
    S s;

    fn1<S,3>(s);
}

which leads to:

$ g++ -c t.cpp
t.cpp: In function ‘void fn1(T&)’:
t.cpp:4:11: error: expected primary-expression before ‘)’ token
  t.fn2<s>();
           ^
t.cpp: In instantiation of ‘void fn1(T&) [with T = S; int s = 3]’:
t.cpp:18:12:   required from here
t.cpp:4:7: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator<’
  t.fn2<s>();
Klamer Schutte
  • 1,063
  • 9
  • 18

0 Answers0