有没有办法让b
的注释定义有效?
template <typename t0>
struct comp_impl
{
t0 g;
template <typename t1>
t0 h(t1 x)
{
return g;
};
};
template <typename t0, typename t1>
void foo()
{
// WORKS
int (comp_impl<int>::*a)(int) = &comp_impl<int>::h<int>;
// FAILS
// t0 (comp_impl<t0>::*b)(t1) = &comp_impl<t0>::h<t1>;
}
void bar()
{
foo<int, int>();
}
错误是:
comp-3.cpp: In function ‘void foo()’:
comp-3.cpp:19:51: error: expected primary-expression before ‘>’ token
t0 (comp_impl<t0>::*b)(t1) = &comp_impl<t0>::h<t1>;
^
comp-3.cpp:19:52: error: expected primary-expression before ‘;’ token
t0 (comp_impl<t0>::*b)(t1) = &comp_impl<t0>::h<t1>;