指向模板函数内模板类的模板方法的指针

时间:2016-11-03 20:30:07

标签: c++ c++11

有没有办法让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>;

0 个答案:

没有答案