0

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
James M
  • 18,506
  • 3
  • 48
  • 56

1 Answers1

3

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

davmac
  • 20,150
  • 1
  • 40
  • 68