1

I have a C++ Class CustomMap that implements QMap like so..

template <class Key, class T> class CustomMap : public QMap<Key, T>

Now, in a function:

template <class MK, class IK, class TK> static TK _at(MK *map, int idx){
...
QMap<int, Key>::Iterator a;
QMap<int, Key>::Iterator b;
...
}

However, multiple errors come about from just these few lines of code...

error: unknown type name 'Iterator'
  virtual Iterator insert(const Key &key, const T &value)
error: expected ';' after expression
    QMap<int, Key>::Iterator a;
        ^
        ;
error: expected ';' after expression
    QMap<int, Key>::Iterator b;
        ^
        ;

I'm already doing #include <QMap> in the header the iterator is defined, and typedef iterator Iterator also occurs inside the Qt QMap object.

I have the exact same code compiling and running under Visual Studio using msvc compiler. The errors are appearing using Clang on OSX.

My setup involves:

  • OSX
  • Clang
  • Qt 5.4
  • All include folders are set and everything else builds fine.

Edit: If I define the Iterator as QMap<int, QString>::Iterator a instead of QMap<int,Key>::Iterator a, it removes the errors. Can this behaviour be explained? From what I see, it's a virtually identical implementation to the original QMap

0 Answers0