g ++错误:预期;在“it”之前。 [英] g++ error: expected ; before "it"

查看:131
本文介绍了g ++错误:预期;在“it”之前。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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


推荐答案

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

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

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

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.

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

这篇关于g ++错误:预期;在“it”之前。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆