Following code example using alias declaration new in C++11 fails to compile with VC++ 11, update 1 in VS2012 and emits included errors. It compiles and executes without a peep with GCC 4.7.2 under MinGW on Windows 7 using g++ -std=c++11 -Wall in.cpp
.
I didn't find any indications that this isn't supported. Furthermore, IntelliSense doesn't pick up any errors and displays a tooltip for cdptr
type that says typedef const double *cdptr
. My project is set to use v110 platform toolset and compile as C++ code.
How have I wronged Microsoft?
#include <iostream>
int main()
{
using cdptr = const double*;
const double pi = 3.14159;
cdptr cdp = π
std::cout << "cdp: " << (*cdp) << std::endl;
return 0;
}
Build output:
1>------ Build started: Project: AliasDeclTest, Configuration: Debug Win32 ------
1> AliasDeclTest.cpp
1>f:\aliasdecltest\aliasdecltest.cpp(9): error C2143: syntax error : missing ';' before '='
1>f:\aliasdecltest\aliasdecltest.cpp(9): error C2873: 'cdptr' : symbol cannot be used in a using-declaration
1>f:\aliasdecltest\aliasdecltest.cpp(12): error C2065: 'cdptr' : undeclared identifier
1>f:\aliasdecltest\aliasdecltest.cpp(12): error C2146: syntax error : missing ';' before identifier 'cdp'
1>f:\aliasdecltest\aliasdecltest.cpp(12): error C2065: 'cdp' : undeclared identifier
1>f:\aliasdecltest\aliasdecltest.cpp(14): error C2065: 'cdp' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The alias syntax The syntax for creating an alias is easy. You type the word "alias", followed by the name you want to give the alias, stick in an = sign and then add the command you want it to run – generally enclosed in single or double quotes.
You can use an alias declaration to declare a name to use as a synonym for a previously declared type. (This mechanism is also referred to informally as a type alias). You can also use this mechanism to create an alias template, which can be useful for custom allocators.
In C++, 'using' and 'typedef' performs the same task of declaring the type alias. There is no major difference between the two. 'Using' in C++ is considered to define the type synonyms.
C++ is not the alias of C# programming language.
MSVC11, even with the November CTP, does not implement using alias declarations.
You can find a table of C++11 support here.
Based on this, it appears Visual Studio 2012 does not yet support type aliases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With