【问题标题】:Missing type specifier on virtual function implementation虚函数实现中缺少类型说明符
【发布时间】:2016-09-19 03:11:58
【问题描述】:

我有以下类结构(在 C++ 中):

template<T>
class A {
    class B {
        class C_Base {
            virtual int foo(const T &a, const T &b) = 0;
        };

        template<U>
        class C final : public C_Base {
            const U &x;
            virtual int foo(const T &a, const T &b) {
                return x(a, b);
            }
        };
    };
};

但是,MSVC 在C 内的foo 的定义上给出了错误missing type specifier - int assumed. Note: C++ does not support default-int.。为什么会这样,如何解决?

【问题讨论】:

  • 你在编造一些东西。尝试编译此代码将在第一行立即失败:template&lt;T&gt;。修复这些错误使其在 MSVC 中编译没有任何问题。

标签: c++ templates c++11 visual-c++ virtual-functions


【解决方案1】:

您忘记了 typename 关键字。

template<typename T>
//-------^^^^^^^^

【讨论】:

  • 这是多么漫长的一天......谢谢你,我不敢相信我忘记了这样的事情......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多