简体   繁体   中英

C++ template not compiling on Linux GCC

I have a piece of code which compiles fine on Microsoft Visual Studio, but not on Linux Eclipse GCC.

This is the code:

template <class KEY, class BASEMAP>
class CGenericKeyToPointerMap : public std::map<KEY, BASEMAP>
{
private:
    iterator        tmpSearchIterator;

};

The compilation output is:

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

Another reason to avoid the use of

using namespace std;

I'm guessing you want to use std::map<KEY, BASEMAP>::iterator instead of std::iterator in the line

iterator        tmpSearchIterator;

In that case, use

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM