C 模板未在Linux GCC上编译
C++ template not compiling on 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;
相关文章:
- 为什么 gcc 编译这个而 msvc 没有
- 错误:使用 clang 没有可行的重载,使用 GCC 编译
- 带有自动参数的函数使用 GCC 编译,但不使用 Visual C++ 编译
- 使用 MINGW gcc 编译时,不会为 std::string 调用重载的新运算符
- Steam 回调在 Linux / GCC 编译期间触发警告
- 在其他容器中使用 boost::container::static_vector 时,GCC 编译错误"将'const s'绑定到类型's&'的引用丢弃限定符"
- 如何使用 GCC 编译指示启用选项 '-Werror'?
- 如何实现使用 gcc-4.4 编译的大向量初始化?
- 关于这个在 Linux 上使用 gcc 编译的程序中的 vtable,nm 告诉我什么?
- 使用 TDM GCC 5.1.0 编译 PDCurses36 时出错
- 为什么这段代码无法使用 gcc 4.8.5 编译,而使用 clang 编译正常
- 使用 std::addressof 时出现 GCC 7 编译错误
- 在类模板上使用 arm gcc 编译期间的隔离错误
- 使用 GCC 编译C++时如何包含 C11 标头?
- 类数据成员指针的非类型模板参数包无法使用 gcc 编译
- 是否可以使用 GCC 编译具有特定编译器标志的代码文件的一部分?
- 将 cctype 函数分配给 std::function,gcc 编译错误
- GCC 编译时出现警告:未知转义序列:"\040"
- 为什么以下代码不使用GCC编译,而是用Clang编译罚款
- GCC编译器,为较低版本的GCC编译应用程序