这个想法是为S类的特定函数提供编译时整数元素,用于不同的类型,例如S.
G ++不允许使用以下代码。谁能帮我解决这个问题?
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);
}
导致:
$ 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>();