【发布时间】:2013-12-04 13:55:10
【问题描述】:
这段代码有什么问题?由于这个答案,我认为我可以转换:
Is it safe to "upcast" a method pointer and use it with base class pointer?
struct B
{
void f(){}
};
struct D : B
{
virtual ~D(){}
};
template <typename FP, FP fp>
void g()
{
}
int main()
{
g<void (D::*)(), &B::f>();
return 0;
}
错误:
t.cpp:18:27: error: could not convert template argument '&B::f' to 'void (D::*)()'
g<void (D::*)(), &B::f>();
这也不起作用:
g<void (D::*)(), static_cast<void (D::*)()>(&B::f)>();
【问题讨论】:
-
@PeteBecker 我也尝试过强制转换,没有运气。