【问题标题】:VS2019 explicit specialization requires template<> error with 'using' keywordVS2019 显式专业化需要带有“使用”关键字的模板<>错误
【发布时间】:2021-12-31 11:47:42
【问题描述】:

我有这段c++代码,VS2019来编译它:

#include <iostream>
template<typename t>
class c
{

};

int main(){
    using o = class c<int>;
}

有没有人知道为什么它不能编译,抱怨:

Error   C2906   'c<int>': explicit specialization requires 'template <>'

使用 mingw-gcc 编译和运行没有错误。

您可以在此处比较编译器输出:https://godbolt.org/z/55fMzh8qz

提前致谢。

【问题讨论】:

  • 微软正在严格控制饮食。 this 有帮助吗?
  • 代码中没有second&lt;int&gt;class 在那里绝对不需要。
  • 谢谢@S.M.它实际上在没有 class 关键字的情况下编译。

标签: c++ templates visual-studio-2019 using


【解决方案1】:

class 在 using 语句中是不必要的,我认为 Visual Studio 认为您正在尝试声明 c 的专业化:

template <>
class c<int>;

因此出现错误消息。

你只需要:

using o = c<int>;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    相关资源
    最近更新 更多