2012-04-24 52 views
9

請解釋SWIG的這些警告以及如何避免它?當SWIG生成C++代碼下的Android NDK編譯什麼是SWIG的警告503?

Warning 503: Can't wrap 'operator()' unless renamed to a valid identifier. 
Warning 503: Can't wrap 'operator =' unless renamed to a valid identifier. 
Warning 503: Can't wrap 'operator *' unless renamed to a valid identifier. 

的警告生成。

+8

這不是G ++警告,它是SWIG警告。 – Flexo 2012-04-24 11:27:35

+1

我想說,看起來更像SWIG。除非你想從Java使用這些運算符,否則這不是問題。 – 2012-04-24 11:28:12

+0

感謝您的信息,我編輯了我的問題。 – arsalank2 2012-04-25 12:06:43

回答

13

與C++相同,Java沒有相同的operator()operator=,所以SWIG無法直接包裝它。因爲它們可能很重要,所以會顯示一條警告,說明它們未被包裝。 (缺少operator=有時可能會特別糟糕)。

%module Sample 

struct test { 
    bool operator()(); 
}; 

但是你可以沉默的警告,告訴呷直接說像露出運營商作爲一個普通的成員函數:

%module Sample 

%rename(something_else) operator(); 

struct test { 
    bool operator()(); 
}; 

此代碼運行swig -Wall -c++ -java時表現出這樣的警告

這會在生成的包裝器中添加一個名爲something_else的函數,而不是operator()

或者你可以斷言痛飲,忽略那些只是罰款使用:

%ignore operator() 

(您也可以通過與類名符合條件的經營者或者適用這些指令的廣泛少)。

3

如果您想以目標語言使用它們,您需要在SWIG中以特殊方式處理重載操作符。見here

相關問題