别名使用vs typedef
alias using vs typedef
我在学校实验室工作,说明书上写着:
将定义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
您可以在这里看到解决方案:
#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()
{
}
- http://ideone.com/9mCaq0(C++)错误:"Word_List"之前应有嵌套的名称说明符
- http://ideone.com/FdIKcr(C++11)成功
您有一个配置错误,您没有使用C++11规范进行编译。
相关文章:
- C++:TypeDef使用元组
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 如何为模板化对象创建模板向量?VS正在投掷C3203
- 数据成员SFINAE的C++17测试:gcc vs clang
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 正在VS调试器中监视映射条目
- Confusion: decltype vs std::function
- 将IBM Rhapsody模型集成到VS 2019中
- 有没有一种方法可以通过"typedef"为重新定义的基本类型定义特征和强制转换运算符
- VS Code "command":"make"与终端窗口中的命令行"make"不同
- typedef struct vs struct - "struct"的存储大小未知
- C++ typedef struct vs class
- 使用 vs typedef 指针到noexcept-function不一致
- const int*& vs typedef int* IntPtr
- const T* vs typedef
- C++使用别名访问嵌套类型(使用 vs typedef)
- using vs. typedef for std::vector::iterator
- 别名使用vs typedef
- C++11,使用 vs typedef,模板化