Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

python

swig

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?

like image 978
Homunculus Reticulli Avatar asked Nov 12 '11 03:11

Homunculus Reticulli


2 Answers

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.

like image 163
Dani Avatar answered Oct 14 '22 02:10

Dani


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.

like image 6
Mark Tolonen Avatar answered Oct 14 '22 03:10

Mark Tolonen