g ++错误:预期;在“它”之前

时间:2014-07-04 16:44:49

标签: linux gcc g++

我将C ++应用程序从Solaris移植到Linux,我遇到了以下错误。代码是:

template <class MapSuperClass> class FWPointerMap : public MapSuperClass
{
  public:
    FWPointerMap()
    {
      _wipe = false;
    }

    FWPointerMap(const MapSuperClass* mMap)
    {
      MapSuperClass::const_iterator it = mMap->begin(); // line 50
      while(it != mMap->end())
      {
        insert(MapSuperClass::value_type((*it).first, (*it).second));
        it++;
      }
      _wipe = false;
    }

我收到以下错误:

../../framework/fwcore/hdr/FWPointerMap: In constructor FWPointerMap<MapSuperClass>::FWPointerMap(const MapSuperClass*):
../../framework/fwcore/hdr/FWPointerMap:50: error: expected ; before it
../../framework/fwcore/hdr/FWPointerMap:52: error: it was not declared in this scope

1 个答案:

答案 0 :(得分:3)

我认为你只需要添加'typename'来告诉编译器MapSuperClass :: const_iterator是一个类型:

typename MapSuperClass::const_iterator it = mMap->begin(); // line 50

因为MaySuperClass是一个类模板参数,所以假设const_iterator成员是一个字段。使用typename通知编译器它实际上是一个类型。

更多信息:http://en.wikipedia.org/wiki/Typename#A_method_for_indicating_that_a_dependent_name_is_a_type