编译器错误预期的nested-name说明符 [英] compiler error expected nested-name specifier

查看:183
本文介绍了编译器错误预期的nested-name说明符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是针对问题的OP:扩展课程,我在其中获得了一个很好的答案。但是,当我尝试编译代码(为我的项目略微重做),我收到以下消息(行号更改以反映以下示例代码):

I am the OP for the question: Extending a class in which I received an excellent answer. However, as I try to compile the code (reworked slightly for my project) I received the following message (line no. changed to reflect following sample code):

except.h: | 09 | expected nested-name-specifier before ‘handler_t1’

以及许多似乎源于此行的。我对C ++是全新的,我对答案(和即将出现的问题)的研究产生了这样的事实:微软的编译器似乎接受了代码,但是符合标准的不是。

along with many more which seem to stem from this line. I am brand new to C++, and my research into the answer (and the forthcoming problem) has yielded this fact: Microsoft's compiler seems to accept the code, but standards compliant ones do not.

我现在的代码如下:

#include <vector>
namespace except
{
  // several other classes and functions which compile and work already
  // (tested and verified) have been snipped out. Entire code is over
  // 1000 lines.

  class Error_Handler
  {
    public:
      using handler_t1 = bool (*)(except::Logic const&);
      std::vector<handler_t1> logic_handlers;

      // a lot more removed because the error has already happened ...
  }
}

链接问题中的代码的阅读向我(以我的有限知识)表明它应该都可以工作。

A read through of the code in the linked question indicates to me (with my limited knowledge) that it should all work.

我的问题是:我需要改变这个声明/定义,以使这可以编译与gcc(4.6.3 64位linux编译与-std = C + + 0x)?

My question therefore is: What do I need to change in this declaration/definition to enable this to compile with gcc (4.6.3 64 bit linux compiling with -std=C++0x)?

推荐答案

GCC 4.6.3不支持C ++ 11类型别名: using handler_t1 = bool Logic const&); 。非模板类型别名等同于typedefs: typedef bool(* handler_t1)(except :: Logic const&); 。替换它们,看看是否有帮助。

GCC 4.6.3 doesn't support C++11 type aliases: using handler_t1 = bool (*)(except::Logic const&);. Non-template type aliases are equivalent to typedefs: typedef bool (*handler_t1)(except::Logic const&);. Replace them and see if that helps.

或者更好,升级到更新的编译器版本。我相信这里的常规响应者倾向于写入由GCC 4.8编译的语言的部分。

Or even better, upgrade to a more recent compiler version. I believe the regular responders here tend to write to the portion of the language compiled by GCC 4.8.

编辑:我在答案中看到的唯一的其他iffy功能是range-为基础,我相信GCC在4.6增加了支持。在用typedef替换类型别名后应该可以。

The only other iffy feature I see in that answer is range-based-for, which I believe GCC added support for in 4.6. You should be OK after replacing the type aliases with typedefs.

这篇关于编译器错误预期的nested-name说明符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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