问题描述
我有一个用于标记为 __declspec(novtable)
的通用可调用对象的基类:
template<class F> struct callable;
template<class R,class... T>
struct __declspec(novtable) callable<R(T...)>
{ virtual R operator()(T...) volatile { return R(); } };
但不知何故这不会错误,如it's supposed to:
int main()
{
auto temp = new callable<void()>();
temp->operator()();
}
为什么 novtable
不起作用?
解决方法
显然,Visual C++ 着眼于模板的 __declspec(novtable)
,而不是它的专业化!
这对我来说没有意义(这是一个错误吗?),但“解决方案”是这样写:
template<class F> struct __declspec(novtable) callable;