Variadic Template in VS 2012 (Visual C++ November 2012 Ctp)

Variadic Template in VS 2012 (Visual C++ November 2012 CTP)

In the Project Properties, make sure to select the Microsoft Visual C++ Compiler Nov 2012 CTP:

Toolchain

The new toolchain does not replace the existing Visual C++ 2012 toolchain, and it is not enabled by default. It's installed side-by-side with the existing toolchain.

If you select the new toolchain, your program will compiler without error.

How can I use C++11 features like delegating constructors in Visual C++ November 2012 CTP?

The error message you quote is being reported by IntelliSense, which does not yet support the new C++11 language features. Note that the full text of the error message reads (emphasis mine):

IntelliSense: "Hero" is not a nonstatic data member or base class of class "Hero"

The announcement for the November CTP states (emphasis mine):

While a new Platform Toolset is provided for convenience of integrating the compiler as part of the Visual Studio 2012 build environment, 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.

The compiler, which is updated by the November CTP, rejects the code with the following errors:

error C2511: 'void Hero::SetName(const std::string &)' : overloaded member function not found in 'Hero'
c:\jm\scratch\test.cpp(6) : see declaration of 'Hero'
error C2511: 'void Hero::SetLevel(const int &)' : overloaded member function not found in 'Hero'
c:\jm\scratch\test.cpp(6) : see declaration of 'Hero'

These errors are expected because your code is ill-formed (the parameters of SetLevel and SetName are passed by value in their inline declarations, and by reference in their definitions). When these errors are fixed, the compiler accepts your code.

C++11 features in Visual Studio 2012

It's worth noting that Visual Studio 2010 already had quite a bit of early C++11 support. So to summarize what is already linked to in other answers, here is what is new in Visual Studio 11 that was not part of Visual Studio 2010:

  • rvalue references to version 2.1 from 2.0
  • lambdas to version 1.1 from 1.0.
  • decltype to version 1.1 from 1.0(not yet available in developer preview)
  • Improved, but still incomplete, Alignment
  • completed strongly-typed enums
  • forward declared enums
  • Standard layout and trivial types
  • Atomics
  • Strong compare and exchange
  • Bi-directional fences
  • Data-dependency ordering
  • Range-based for loop

In early November 2012, Microsoft announced the Visual C++ Compiler November 2012 CTP, which adds more C++11 functionality to Visual Studio 2012:

  • uniform initialization
  • initializer lists
  • variadic templates
  • function template default arguments
  • delegating constructors
  • explicit conversion operators
  • raw strings

Bug in variadic function template specialization with MSVC?

  1. This is perfectly legitimate code; both gcc-4.7.2 and clang 3.0 accept it.

  2. Try searching Microsoft Connect.



Related Topics



Leave a reply



Submit