2

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

将定义 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()
{
 ...
}

附加信息:

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
4

1 回答 1

7

You can see the solution here:

#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()
{
}

You have a configuration error, you are not compiling with C++11 specification.

于 2013-02-21T16:26:45.037 回答