问题
Looking through the new features of C++11, delegating constructors seems like they would be particular useful in my situation.
Unfortunately, I need to use Visual Studio. The project I am working on has a several month deadline and using experimental/broken compilers doesn't concern me. Is there a version of Visual C++ that can will let me do constructor delegation?
See http://www.stroustrup.com/C++11FAQ.html#inheriting
回答1:
Yes, there is a beta version of the compiler that supports delegating constructors - the Visual C++ Compiler November 2012 CTP.
回答2:
In the meanwhile, try
#define INHERIT_CONSTRUCTOR(BaseName,DerivedName) template <class... Args> DerivedName(Args&&... args) : BaseName(std::forward<Args>(args)...) { }
回答3:
Once you've successfully installed the CTP via the link given above by Karel Petranek, just create any old C++ project.
Then, under the project's 'Property Pages > Configuration Properties > General > Platform Toolset', choose "Microsoft Visual C++ Compiler Nov 2012 CTP (v120_CTP_Nov2012)".
That's all. Now you have access to these additional C++ compiler features in VS2012.
回答4:
You don't have to install CTP anymore.
Visual Studio 2013 will support delegating constructors and you can try the Preview version which is available by now.
来源:https://stackoverflow.com/questions/14432802/is-there-a-way-to-use-delegating-constructors-in-visual-studio-2012