继承 MSVC 2017 中的模板构造函数和错误 C2600
Inheriting template constructor and error C2600 in MSVC 2017
我在VS 2017 15.9.4(工具集v141)上遇到了编译错误,它曾经与VS 2015(工具集v140)一起使用。问题在于从基类继承模板化构造函数。
#include <type_traits>
template <typename T>
class IAttribute {
public:
template <
typename U = T,
typename = typename std::enable_if<std::is_default_constructible<U>::value>::type
>
IAttribute() {}
IAttribute(T* value) {
}
private:
T* m_value;
};
class AttributeInt : public IAttribute<int> {
public:
using IAttribute<int>::IAttribute;
AttributeInt();
};
AttributeInt::AttributeInt() : IAttribute<int>(nullptr) {
}
int main() {
AttributeInt qq;
}
在最新的VS中,我收到错误:
错误 C2600:"AttributeInt::AttributeInt":无法定义编译器生成的特殊成员函数(必须先在类中声明)
一段时间后,我发现将构造函数实现AttributeInt()
移动到类定义主体可以修复错误。
class AttributeInt : public IAttribute<int> {
public:
using IAttribute<int>::IAttribute;
AttributeInt() : IAttribute<int>(nullptr) {}
};
然而,这并不能解决我的问题,因为在我的项目中,我需要构造依赖于这个类的派生类。任何想法如何在不移动实现的情况下解决此问题?
无论如何,原始代码适用于GCC 8.2,clang 7.0.0,zapc++ 2017.08和MSVC 2015。
> 它在VS 2017中被确认为错误,并在VS 2019 16.0.0预览版1中修复 - 在此处确认。无论如何,感谢您的帮助!
相关文章:
- "error: no matching function for call to"构造函数错误
- 为什么类中的ostringstream类型的成员会导致";调用隐含删除复制构造函数";错误
- C++ OpenCV 卡尔曼滤波器构造函数错误
- 结构数组的构造函数错误,错误消息:没有构造函数实例与参数列表匹配
- C++ 中常量属性的初始化构造函数错误
- STL向量上出现奇怪的复制构造函数错误
- C++ 乘法定义的构造函数错误消息似乎错误
- 通过构造函数错误地播种梅森扭曲
- C++ 多态构造函数错误;标识符未定义
- 类组合中的构造函数错误
- C++中的构造函数错误
- 构造函数错误:错误:数字常量之前的预期“”,“”或“..”
- 这个奇怪的复制构造函数错误抱怨的是什么
- Singleton子类构造函数错误
- 默认构造函数错误 (C++)
- 基类构造函数错误
- 初始化列表构造函数错误带有CRTP
- C++可能存在写入位置的构造函数错误冲突
- 构造函数错误:需要标识符
- 复制构造函数错误:对象的类型限定符与成员函数不兼容