Visual Studio 2017 不允许我创建 C++ 专用模板

Visual Studio 2017 won't let me create c++ specialized template

本文关键字:C++ 专用 创建 允许我 Studio 2017 不允许 Visual      更新时间:2023-10-16
template<> 
class A<char> { // Error here
public:
A(char c)
{
// Do something here.
}
};

当我将鼠标悬停在 A 上时,它说"A 不是模板"。

您需要先声明模板,然后才能对其进行专用化:

// declare the template
template <typename T>   // no need to define it
struct A;               // if you only want the specialization
// declare and define the specialization
template<> 
struct A<char> {};