c++ - C++ 模板未在 Linux GCC 上编译
问题描述
我有一段代码在 Microsoft Visual Studio 上编译得很好,但在 Linux Eclipse GCC 上编译得不好。
这是代码:
template <class KEY, class BASEMAP>
class CGenericKeyToPointerMap : public std::map<KEY, BASEMAP>
{
private:
iterator tmpSearchIterator;
};
编译输出为:
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/test.d" -MT"src/test.o" -o "src/test.o" "../src/test.cpp"
../src/test.cpp:22:2: error: invalid use of template-name ‘std::iterator’ without an argument list
iterator tmpSearchIterator;
^~~~~~~~
../src/test.cpp:22:2: note: class template argument deduction is only available with -std=c++17 or -std=gnu++17
In file included from /usr/include/c++/8/bits/stl_algobase.h:65,
from /usr/include/c++/8/bits/char_traits.h:39,
from /usr/include/c++/8/ios:40,
from /usr/include/c++/8/ostream:38,
from /usr/include/c++/8/iostream:39,
from ../src/test.cpp:9:
/usr/include/c++/8/bits/stl_iterator_base_types.h:118:12: note: ‘template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> struct std::iterator’ declared here
struct iterator
解决方案
避免使用的另一个原因
using namespace std;
我猜你想使用std::map<KEY, BASEMAP>::iterator
而不是std::iterator
排队
iterator tmpSearchIterator;
在这种情况下,使用
using iterator = typename std::map<KEY, BASEMAP>::iterator;
iterator tmpSearchIterator;
推荐阅读
- docker - 如何从 dockerised nginx 使用 cpprest 到达另外两个容器
- tensorflow - 我不清楚 Conv2DTranspose 参数
- javascript - 将两个或多个文件附件从 Mozilla Thunderbird 拖到 dropzoneJS 不起作用
- amazon-web-services - quicksight 密集排名但排除空值
- sql - plsql查询抛出带引号的字符串未终止错误
- mysql - 如何在 MySQL 查询中选择查询某个值?
- react-native - 如何使 BottomTabBar 上的图标扩展 BottomTabBar
- html - Blazor 应用程序中的 EditForm 有多个提交按钮
- reactjs - Axios NTLM 不适用于 POST(但适用于 GET)
- python - Celery/Django 工作人员检测何时没有工作