SWIG C++ to Python: Warning(362): operator= ignored

大憨熊 提交于 2019-12-08 15:44:05

问题


I am exporting a C++ class to Python and I noticed that during compilation, SWIG issued the following warning:

Warning(362): operator= ignored

I am not sure why the operator is being overloaded, because it says in the SWIG documentation, that SWIG is capable of handling operators such as the assignment operator

There is nothing special about my class, it is declared like this:

class Foo
{
public:
    Foo();
    Foo& operator= (const Foo&); 
    // etc ..
};

Why is SWIG failing to generate wrapper code for the assignment operator, and how may I fix this?


回答1:


There is no assignment in python (other than in primitive types), only assignment of pointers. If you want to create a copy, you need a special copy function.




回答2:


Read the last line of your documentation link (section 31.3.11):

Also, be aware that certain operators don't map cleanly to Python. For instance, overloaded assignment operators don't map to Python semantics and will be ignored.



来源:https://stackoverflow.com/questions/8102244/swig-c-to-python-warning362-operator-ignored

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!