这个问题实际上是关于SWIG的,而不是缺少分号的基本C ++。
我在类中(在头文件中)有以下方法:
class BarClass
{
// ... more code goes here
unsigned int foo(unsigned int val) throw(std::invalid_argument) override;
// ... more code goes here
};
我有以下形式的SWIG接口声明:
%include "stdint.i"
%include "std_except.i"
%include "exception.i"
%module mymodule
%{
#include "headerFile.h"
%}
%include "headerFile.h"
代码用作C ++静态库,但也通过SWIG暴露给python。使用GCC / Clang进行正常编译效果很好。
但是,在使用SWIG包装库时,我收到错误:
headerFile.h:22:错误:语法错误 - 可能缺少分号。
我可以用以下方法替换方法声明:
unsigned int foo(unsigned int val) throw(std::invalid_argument);
当删除覆盖时,SWIG似乎可以工作,但我收到警告。我的印象是SWIG同时被throw和override的组合弄糊涂了。
这是SWIG的错误还是我想念的傻事?
注意:我非常清楚使用throw声明已被弃用,但这是SWIG获取有关异常的信息并为Python生成适当代码的方式。也许在SWIG中有更好/更新的方法吗?
答案 0 :(得分:5)
您的SWIG正在使用C ++ 11:
http://www.swig.org/Doc3.0/CPlusPlus11.html
7.2.11显式覆盖和final:特殊标识符final和override可用于方法和析构函数,如下例所示:
virtual void ef() final override;
virtual ~DerivedStruct() override;
您可以:
-std=c++11
)#define override