C++11 typedef 别名编译错误

标签 c++ c++11 alias typedef

当我尝试编译它时,出现以下错误:

error: expected unqualified-id before ‘using’

我知道,这个问题之前被问过好几次了,但我没有找到答案。通常他们说头文件之一缺少分号。但现在情况并非如此。当然,我使用 -std=c++0x 标志

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


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

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


    return 0;
}

最佳答案

您的错误is caused事实上template aliases with using是 C++11 功能,但您的编译器不支持它。您应该在编译时添加相应的标志。最有可能的是:

-std=c++11

(至少对于 g++clang++)。

Live demo

否则你的编译器还不支持它们。海湾合作委员会supports them from 4.7 .

关于C++11 typedef 别名编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22919912/

相关文章:

mysql - 使用 Cakephp 无法获得正确的别名

java - 如何将别名添加到 Android (Java) Keystore

c++ - 每个#include 指令预处理器的时间成本是多少?

c++ - 不存在从 "std::string"到 "PVOID"的合适转换函数

c++ - 如何从 lambda 中的函数返回?

c++ - 以后可以使用分配器构造 std::tuple 的元素吗?

c++ - 重命名命名空间

c++ - Node-expat 错误的 ELF 类 : ELFCLASS64

c++ - Flutter和Linux

c++ - 为什么下面的多线程代码会导致 SIGABRT ?