簡體   English   中英

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::map<KEY, BASEMAP>::iterator而不是std::iterator

iterator        tmpSearchIterator;

在那種情況下,使用

using iterator = typename std::map<KEY, BASEMAP>::iterator;
iterator        tmpSearchIterator;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM