使用vs typedef的别名

时间:2013-02-21 15:28:12

标签: c++ c++11 alias typedef using

我正在学校的实验室工作,并在说明中说:

  

将定义Word_List的typedef更改为别名声明(使用)

从我用谷歌搜索过的方式来看,改变方法是:

typedef vector<Word_Entry> Word_List;

为:

using Word_List = std::vector<Word_Entry>;

但是当我编译时,我收到以下错误:

error: expected nested-name-specifier before 'Word_List'

大部分代码:

#include <iostream>
#include <algorithm>
#include <list>
#include <string>
#include <vector>
#include <fstream>
#include <cctype>
#include <iomanip>

using namespace std;

struct Word_Entry
{
  string ord;
  unsigned cnt;
};

//typedef vector<Word_Entry> Word_List; <-This is what it used to look like
using Word_List = vector<Word_Entry>;


int main()
{
 ...
}

aditional info:

Yes, I am compiling with c++11 
Word_Entry is a struct that stores 2 variables
I have the line "using namespace std;" in the begining of my code
I'm using mingw compiler

1 个答案:

答案 0 :(得分:7)

您可以在此处查看解决方案:

#include <string>
#include <vector>

using namespace std;

struct Word_Entry
{
  string ord;
  unsigned cnt;
};

//typedef vector<Word_Entry> Word_List; <-This is what it used to look like
using Word_List = vector<Word_Entry>;


int main()
{
}

您有一个配置错误,您没有使用C ++ 11规范进行编译。