7

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

Mikhail
  • 7,749
  • 11
  • 62
  • 136
  • 4
    Your question is slightly confused - do not mix up the inheritance of constructors with the C++11 feature _delegating constructors_. I have removed your link to the former, since you are in fact asking about the latter. – Lightness Races in Orbit Jan 21 '13 at 06:11
  • Almost the same question: http://stackoverflow.com/questions/14416574/how-can-i-use-c11-features-like-delegating-constructors-in-visual-c-november – Lightness Races in Orbit Jan 21 '13 at 06:13

4 Answers4

9

Yes, there is a beta version of the compiler that supports delegating constructors - the Visual C++ Compiler November 2012 CTP.

Karel Petranek
  • 15,005
  • 4
  • 44
  • 68
  • 5
    [Careful, though](http://stackoverflow.com/a/14431812/560648): `the VS 2012 IDE, Intellisense, debugger, static analysis, and other tools remain essentially unchanged and do not yet provide support for these new C++11 features.` – Lightness Races in Orbit Jan 21 '13 at 06:13
  • Was this released as update 1? I can't seem to get it to take up my code. How do we actually get it to compile the code? Pass it in as a textfile? – Mikhail Jan 21 '13 at 06:36
  • 2
    @Mikhail This is going to be released as update 2. For now, it is just a CTP. – Agentlien Jan 21 '13 at 06:43
  • 1
    It can be added as a compiler to VS. See info at the download page. – Karel Petranek Jan 21 '13 at 09:34
  • 1
    It is not part of any "Update" nor will it ever be. The CTP stands as it is and needs to be installed _in addition_ to the newest update. However, VS2013 supports all of the CTP features and more. – Ela782 Jul 29 '13 at 18:49
3

In the meanwhile, try

#define INHERIT_CONSTRUCTOR(BaseName,DerivedName) template <class... Args> DerivedName(Args&&... args) : BaseName(std::forward<Args>(args)...) { }
Cookie
  • 12,004
  • 13
  • 54
  • 83
  • 1
    This looks straight forward enough. Compact solution. I'm trying it out now. *IntelliSense* is happy. I haven't compiled yet (and won't for a while--code is not nearly ripe enough for that), won'. There must be some gotcha in there somewhere, haven't found it yet. – riderBill Feb 13 '16 at 06:49
1

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.

1

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.