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

user34537 picture user34537 · Nov 5, 2012 · Viewed 12.5k times · Source

I installed Visual C++ Compiler November 2012 CTP and created a C++ console project. I wrote this in

template<typename T>
void Test(T value){
}
template<typename T, typename... Args>
void Test(T value, Args... args){
    Test(value);
    Test(args...);
}

int main(){
    Test(1,2,3);
}

Then I pressed F6 to build in the IDE. I got this error on line 4

error C2143: syntax error : missing ',' before '...'

The compile list "variadic templates" so I believe this should work. I do understand intellisense may be incorrect however the 'compiler' should work. Can I not build from the IDE? Do I have to enable something somewhere? int i{4}; doesn't seem to work either and I am sure thats valid uniform initialization.

Answer

James McNellis picture James McNellis · Nov 5, 2012

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.