[英]C++11's Delegating Constructors in Visual Studio 2012
I am trying to use delegating constructors in Visual Studio 2012. The following code compiles in Xcode 4.6 but not in Visual Studio 2012: 我试图在Visual Studio 2012中使用委托构造函数。以下代码在Xcode 4.6中编译,但在Visual Studio 2012中不编译:
In the .h file 在.h文件中
class ErrorReportDlg : public QDialog
{
public:
ErrorReportDlg(OwlExceptionPtr ex, QWidget *parent);
ErrorReportDlg(QWidget *parent);
virtual ~ErrorReportDlg();
}
In the .cpp file 在.cpp文件中
// FWIW, OwlExceptionPtr is
// typdef boost::shared_ptr<OwlException> OwlExceptionPtr
ErrorReportDlg::ErrorReportDlg(OwlExceptionPtr ex, QWidget *parent)
: QDialog(parent),
_error(ex)
{
// stuff
}
ErrorReportDlg::ErrorReportDlg(QWidget *parent)
: ErrorReportDlg(OwlExceptionPtr(), parent) // <--- error here
{
// do nothing
}
The error I'm getting is: 我得到的错误是:
error C2437: 'ErrorReportDlg' : already initialized
错误C2437:'ErrorReportDlg':已初始化
What am I doing wrong? 我究竟做错了什么? Thank you!
谢谢!
As per MSDN , VS 2012 doesn't support delegating constructors out of the box. 根据MSDN ,VS 2012不支持委托构造函数开箱即用。
You get delegating constructors (and a bunch of other C++11 features) when you install the November 2012 CTP (Compiler Technical Preview). 安装2012年11月的CTP (编译器技术预览版)时,您可以委派构造函数(以及一堆其他C ++ 11特性)。 After installing, switch your project to use the CTP as its toolset (via
Project properties
), and you're set. 安装后,切换项目以使用CTP作为其工具集(通过
Project properties
),然后进行设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.