我是这个问题的 OP: 扩展一个我收到了很好答案的课程。但是,当我尝试编译代码时(对我的项目进行了轻微修改),我收到了以下消息(行号已更改以反映以下示例代码):
except.h: | 09 | expected nested-name-specifier before ‘handler_t1’
以及更多似乎源于这条线的东西。我是 C++ 的新手,我对答案(以及即将出现的问题)的研究得出了这样一个事实:微软的编译器似乎接受了代码,但符合标准的编译器却不接受。
我目前拥有的代码如下:
#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 ...
}
}
通读链接问题中的代码向我表明(以我有限的知识)它应该都可以工作。
因此,我的问题是:我需要在此声明/定义中进行哪些更改以使其能够使用 gcc 进行编译(使用 -std=C++0x 编译的 4.6.3 64 位 linux)?
原文由 Jase 发布,翻译遵循 CC BY-SA 4.0 许可协议
GCC 4.6.3 不支持 C++11 类型别名:
using handler_t1 = bool (*)(except::Logic const&);
。非模板类型别名等价于 typedefs:typedef bool (*handler_t1)(except::Logic const&);
。更换它们,看看是否有帮助。或者更好的是,升级到更新的编译器版本。我相信这里的常规响应者倾向于写入由 GCC 4.8 编译的语言部分。
编辑:我在该答案中看到的唯一其他不确定的功能是基于范围的,我相信 GCC 在 4.6 中增加了对它的支持。用 typedef 替换类型别名后应该没问题。