简体   繁体   中英

C++11 typedef alias compile error

When I try to compile this, I get the following error:

error: expected unqualified-id before ‘using’

I know, this was asked several times before, but I didn't find the answer. Usually they say that a semicolon is missing in one of the header files. But it's not the case now. And of course I use the -std=c++0x flag

#include <iostream>
#include <string>
#include <vector>


template <typename T>
using stringpair = std::pair<std::string, T>;

int main (int argc, char* argv[]) {


    return 0;
}

Your error is caused by the fact that template aliases with using is a C++11 feature and your compiler does not support it. You should add the corresponding flags at compilation. Those most likely are:

-std=c++11

(at least for g++ and clang++ ).

Live demo

Otherwise your compiler does not support them yet. GCC supports them from 4.7 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM