C++11构造函数继承不起作用
C++11 constructor inheritance not working
我尝试了以下代码:
struct Base {
Base(int a) {}
};
struct Derived : Base {
using Base::Base; // Inherit Base's constructors.
};
int _tmain(int argc, _TCHAR* argv[])
{
Derived d(1);
}
这不编译,我得到:
error C2664: 'Derived::Derived(const Derived &)' : cannot convert argument 1 from 'int' to 'const Derived &'
(找不到相关的构造函数,它试图调用默认的复制构造函数)
如何修复继承,以便Derived d(1);
进行编译?
根据http://msdn.microsoft.com/en-us/library/hh567368.aspx构造函数继承未在任何现有的Visual C++编译器中实现:(
然而,如果我们有耐心再等一段时间,根据http://blogs.msdn.com/b/vcblog/archive/2014/06/11/c-11-14-feature-tables-for-visual-studio-14-ctp1.aspx即将发布的版本将对此提供支持。
相关文章:
- 为什么在保护模式下继承升级不起作用
- 将复制构造函数设置为默认值在继承自 QObject 时不起作用
- 带有此指针的模板类多重继承构造函数不起作用?
- 我的二传手在新类中不起作用(继承)
- GCC:当层次结构中存在虚拟继承时,C++11 内联对象初始化(使用 "this")不起作用
- 为什么多个头文件和源文件中的C++继承不起作用?
- C++ 多级继承不起作用
- C++,继承的复制因子不起作用
- C++为什么继承不起作用
- 在C++中实现方法时继承不起作用
- .cpp.模板类继承不起作用
- 似乎头文件被忽略了/继承平原不起作用
- C++继承在堆栈上不起作用
- 使用继承时,带有 CRTP 的类型定义不起作用
- 类继承代码不起作用
- C++11构造函数继承不起作用
- c++中的继承不起作用.编译以下c++代码时发生链接器错误
- 使用模板时,继承不起作用
- 派生类的继承方法不起作用
- 具有继承的重载方法/运算符不起作用