我在这里没有正确使用typeof()吗?
Am I not using typeof() correctly here?
我的代码看起来像这样
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
...
typedef vector<long> vl;
vl numbers;
...
tr(numbers, j) { // this is line 95
...
}
代码对我来说看起来不错,但对我的编译器来说却不行!无情地,我得到了以下错误:
code.cpp: 在函数 'int main((' 中:
code.cpp:95:9:错误:实例化后"std::vector::迭代器"的专用化
code.cpp:95:9:错误:"typeof"之前的预期主表达式
code.cpp:95:9:错误:在"typeof"之前应为";">
code.cpp:95:9:错误:ISO "for"范围更改了"j"的名称查找
code.cpp:95:9:注意:(如果你使用"-fallowive",G++ 将接受你的 代码(
代码.cpp:95:9:错误:与"J!= "中的"运算符!="不匹配 numbers.std::vector<_Tp, _Alloc>::end with _Tp = long int, _Alloc = std::分配器, std::vector<_Tp, _Alloc>::迭代器 = __gnu_cxx::__normal_iterator>, 键入名称 std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::p ointer = 长内*'
我在这里错过了什么?
宏中缺少括号。
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
^
Need ) here
尝试修复它,看看你得到了什么错误。
次要说明 1:迭代时,请使用 ++i
而不是 i++
因为前者通常可以更快地用于迭代器。
次要说明 2:typeof
是 GCC 特定的扩展。您的代码不会在其他编译器上编译。
我认为你缺少一个'('
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
相关文章:
- 努力将整数转换为链表。不知道我在这里做错了什么
- 我可以在这里替换什么,因为我不能在 C# 中使用隐式变量的 lambda 函数?
- 当我从下面的代码中删除关键字 virtual 时,它可以正常工作,否则会出现错误。在这里"virtual"字的意义是什么?
- File.cpp.o:OpenPose 标志 CMakeFiles/.. 的多重定义/main.cpp.o:首先在这里定
- 为什么thread_local变量在这里从未初始化?
- 为什么我必须在这里使用dynamic_cast
- 在这里,当我们比较 if(vc[i]==vc1[i]) 时,它是向量数组. 实际上比较的值是多少,
- 我正在尝试使用 while 循环从字符串中删除字母,直到没有字母。我在这里做错了什么?
- 为什么 C++20 中的 [[可能]] 属性在这里引发警告?
- 我在这里正确传递参数了吗?
- 为什么gmp会在这里与"invalid next size"重新定位一起崩溃?
- 移动语义在这里如何工作?
- 如何在这里循环运行?
- 为什么枚举变量在这里是右值?
- 我的C++合并排序代码不起作用。我在这里错过了什么?
- 试图美化这个Arduino代码[初学者在这里]
- 复制交换习惯用法-我们可以在这里使用动态强制转换操作吗
- 在这里使用删除运算符是否正确,我很困惑
- 如何使用模板生成整数序列在这里工作
- 我在这里没有正确使用typeof()吗?