2013-02-21 53 views
1

我工作的一所学校实验室和指令,它说:别名使用VS的typedef

Change the typedef that defines Word_List to a alias declaration (using)

从我GOOGLE了,要做到这一点的方法是从改变:

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的信息:

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

什么是编译器? – 2013-02-21 15:29:20

+1

您是否对您的项目或生成文件启用了C++ 11规范? – deepmax 2013-02-21 15:30:16

+0

我已添加aditional信息回答你的问题 – 2013-02-21 15:50:44

回答

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规范的编制。

+1

我相信g ++只支持4.7以后的版本。 [用4.7.2测试](http://liveworkspace.org/code/sgxSh$0),[用4.6.3测试](http://liveworkspace.org/code/sgxSh$1) – 2013-02-21 16:29:24