1

我有一个CustomMap像这样实现 QMap 的 C++ 类。

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

现在,在一个函数中:

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

然而,仅仅这几行代码就会产生多个错误......

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;
        ^
        ;

我已经#include <QMap>在标题中定义了迭代器,并且typedef iterator Iterator也发生在 Qt QMap 对象中。

我使用 msvc 编译器在 Visual Studio 下编译和运行完全相同的代码。在 OSX 上使用 Clang 出现错误。

我的设置包括:

  • 操作系统
  • Qt 5.4
  • 所有包含文件夹都已设置,其他一切都很好。

编辑:如果我将 Iterator 定义为QMap<int, QString>::Iterator a而不是QMap<int,Key>::Iterator a,它将删除错误。这种行为可以解释吗?据我所知,它与原始实现几乎相同QMap

4

0 回答 0