类模板状态数据成员,而不是可以显式特化的实体
class template state data member, not an entity that can be explicitly specialized
我在下面的代码中得到一个错误:
template<typename T, bool B = is_fundamental<T>::value>
class class_name;
template<>
class class_name<string, false>{
public:
static string const value;
};
template<>
string const class_name<string, false>::value = "Str";
// error: not an entity that can be explicitly specialized.(in VC++)
我该如何修复它?
你在这里混合了两种不同的方法。第一个是@KerrekSB建议的
template<typename T, bool B = is_fundamental<T>::value>
class class_name;
// NOTE: template<> is needed here because this is an explicit specialization of a class template
template<>
class class_name<string, false>{
public:
static string const value;
};
// NOTE: no template<> here, because this is just a definition of an ordinary class member
// (i.e. of the class class_name<string, false>)
string const class_name<string, false>::value = "Str";
或者,您可以完整地编写通用类模板并显式地专门化<string, false>
template<typename T, bool B = is_fundamental<T>::value>
class class_name {
public:
static string const value;
};
// NOTE: template<> is needed here because this is an explicit specialization of a class template member
template<>
string const class_name<string, false>::value = "Str";
相关文章:
- 使用指针重新分析实体
- Constexpr替代了新的放置方式,可以让内存中的对象保持未初始化状态
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 如何使用tinyxml2从XML加载父实体和子实体
- OSX MetalKit CVMetalTextureCacheCreateTextureFromImage失败,状态:
- 不能将 "void *" 类型的值分配给类型 "TCHAR" 的实体
- std::future_error:无关联状态
- 如何避免LED在循环状态变化中闪烁?
- boost 是否有按特殊类型值编码状态"compact optional"?
- 需要帮助在 c++ 中将字符串转换为字符 ----错误 "const char *" 类型的值不能用于初始化 "char" 类型的实体
- 为什么系统函数总是在C++中返回已转移的退出状态?
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 当可输入框在窗口中处于活动状态时获得通知的任何方法
- 如何在 ECS 模型中组织实体?
- 检查两个节点在子节点上是否具有相同状态的更优雅的方法
- 将有状态的 lambda 传递到 C 样式函数中,而无需上下文参数
- 在 nullptr 上调用无状态类的非静态成员函数是否合法?
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 为什么我们不在下面给出的代码中使用指针来实例化C++的实体对象?
- 类模板状态数据成员,而不是可以显式特化的实体