我對C++的類型定義看起來像下面這樣:痛飲一成不變的std ::地圖參考
typedef std::map<int, TestClass> TestClassMap;
我有另一個類返回一個const TestClassMap&
。
然後在我的接口(.I)文件痛飲,我有以下幾點:
namespace std
{
%template(TestClassMap) map<int, myNamespace::TestClass>;
}
編譯沒有問題,並創建了C#庫。
但是,在C#庫中,返回const TestClassMap&
的函數實際上會返回可更改的TestClassMap(可變)。如果我查看返回對象上的IsReadOnly
設置,它是錯誤的。
從看SWIG文檔,它看起來像有一種方法來標記對象爲immutable
,我認爲這是我想要的。但是,我試圖做到這一點,並沒有取得任何成功。我已經試過以下每一項:
%feature("immutable","1") TestClass;
%immutable TestClass;
%immutable
%template(TestClassMap) map<int, myNamespace::TestClass>;
%mutable
有爲什麼const std::map<>&
不能進行一成不變的一些深層的原因?任何其他想法?