Joh*_*son 2 c++ alias typedef using c++11
我正在学校的实验室工作,并在说明中说:
将定义Word_List的typedef更改为别名声明(使用)
从我用Google搜索过的方式来看,改变方法是:
typedef vector<Word_Entry> Word_List;
Run Code Online (Sandbox Code Playgroud)
至:
using Word_List = std::vector<Word_Entry>;
Run Code Online (Sandbox Code Playgroud)
但是当我编译时,我收到以下错误:
error: expected nested-name-specifier before 'Word_List'
Run Code Online (Sandbox Code Playgroud)
大部分代码:
#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()
{
...
}
Run Code Online (Sandbox Code Playgroud)
附加信息:
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
Run Code Online (Sandbox Code Playgroud)
小智 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()
{
}
Run Code Online (Sandbox Code Playgroud)
您有一个配置错误,您没有使用C++ 11规范进行编译.
归档时间: |
|
查看次数: |
3213 次 |
最近记录: |