g++ error: expected ; before “it”

耗尽温柔 提交于 2020-01-03 05:28:07

问题


I'm porting C++ app from Solaris to Linux and I'm stuck with the following error. The code is:

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

And I get the following error:

../../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:


I think you just need to add 'typename' to tell the compiler that MapSuperClass::const_iterator is a type:

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

Because MaySuperClass is a class template parameter, the assumption is that the const_iterator member is a field. Using typename informs the compiler that it is in fact a type.

More information: http://en.wikipedia.org/wiki/Typename#A_method_for_indicating_that_a_dependent_name_is_a_type



来源:https://stackoverflow.com/questions/24578355/g-error-expected-before-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!