【问题标题】:Why doesn't __declspec(novtable) work on a template specialization?为什么 __declspec(novtable) 不适用于模板专业化?
【发布时间】:2021-04-28 23:52:48
【问题描述】:

我有一个通用可调用对象的基类,我将其标记为 __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++ vtable


    【解决方案1】:

    显然 Visual C++ 在模板上查看__declspec(novtable),而不是其特化!
    这对我来说没有意义(这是一个错误吗?),但“解决方案”是这样写:

    template<class F> struct __declspec(novtable) callable;
    

    【讨论】:

      猜你喜欢
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多