Martin Green
Martin Green

Reputation: 1054

Using alias declaration with VC++ 11

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 = &pi;

    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 ==========

Upvotes: 7

Views: 6538

Answers (2)

Yuushi
Yuushi

Reputation: 26080

Based on this, it appears Visual Studio 2012 does not yet support type aliases.

Upvotes: 6

K-ballo
K-ballo

Reputation: 81409

MSVC11, even with the November CTP, does not implement using alias declarations.

You can find a table of C++11 support here.

Upvotes: 12

Related Questions