Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

SWIG: Shadowed c'tors using different enums

Avatar of OliverRudolph
OliverRudolphFlag for Germany asked on
C++Python
3 Comments1 Solution561 ViewsLast Modified:
Hi folks!

Just recently I have begun using SWIG to create an Python interface to my C++ kernel. Now, I feel a little overwhelmed by the possibilities and cannot find the right place to find a solution for the following problem of mine:

I have two different enums and a class with different constructors making use of them, e.g.

enum A { a1, a2, a3 };
enum B { b1, b2, b3 };

class C
{
    C(string s, A a);
    C(string s, B b);
    C(string s, A a, B b);
}


Now when using SWIG on this setup, it gives me a message on the shadowing of c'tor C(string s, B b) by C(string s, A a) as apparently Python doesn't know about enumerations and replaces them with integer values. As it is (obviously) impossible to distinguish between C(string s, int a) and C(string s, int b), the second c'tor cannot be called from Python.

I've seen several entries in the SWIG manuals about typemaps, but I am really not sure how to use them or if they can be applicable and helpful in this case (it's clearly stated, typemaps are of the more advanced topics in SWIG interface generation).

Can anybody help me to resolve this issue?

The use of enumerations in C++ is made this way to enable the use of default parameters without paying respect to the ordering of parameters.


Thank you very much in advance and
best regards!

Oliver
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrixFlag of United Kingdom of Great Britain and Northern Ireland imageSenior Software Engineer (Avast)

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answers