缺少分号:C++或SWIG问题?

Jua*_*eni 2 c++ swig c++11

这个问题实际上是关于SWIG的,而不是缺少分号的基本C++.

我在类中(在头文件中)有以下方法:

class BarClass 
{
    // ... more code goes here
    unsigned int foo(unsigned int val) throw(std::invalid_argument) override;
    // ... more code goes here
};
Run Code Online (Sandbox Code Playgroud)

我在表单中有一个SWIG接口声明:

%include "stdint.i"
%include "std_except.i"
%include "exception.i"

%module mymodule
%{
    #include "headerFile.h"
%}
%include "headerFile.h"
Run Code Online (Sandbox Code Playgroud)

该代码用作C++静态库,但也通过SWIG暴露给python.使用GCC/Clang进行正常编译效果很好.

但是,当使用SWIG包装库时,我收到一个错误:

headerFile.h:22:错误:语法错误 - 可能缺少分号.

我可以用以下方法替换方法声明:

unsigned int foo(unsigned int val) throw(std::invalid_argument);
Run Code Online (Sandbox Code Playgroud)

删除覆盖时,SWIG似乎可以工作,但我收到警告.我的印象是SWIG同时被throw和override的组合弄糊涂了.

这是SWIG的错误还是我想念的傻事?

注意:我非常清楚使用throw声明已被弃用,但这是SWIG获取有关异常的信息并为Python生成适当代码的方式.也许在SWIG中有更好/更新的方法吗?

sha*_*awn 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;
Run Code Online (Sandbox Code Playgroud)

你可以:

  1. 使用C++ 11与C++编译器(例如:-std=c++11)
  2. 禁用SWIG的C++ 11代码生成器.
  3. 使用技巧 #define override