2

I have a C++ class, say B, that is publicly derived from another class, A.

The B class is swigged and made accessible in Python. This works great, and all public functions defined in class B are readily available in Python without almost any work.

However, when creating a B object in Python the public functions that are defined in class A seem not to be exposed, available automatically.

Question is, how do one get access to functions up a C++ class hierarchy for a swigged Python object?

2 Answers 2

3

It seemed the answer was in the actual ordering of include files in the swig interface file.

By placing the baseclass headers BEFORE derived classes, everything seemed to start working as expected.

For anyone "swigging", seeing the warning;

warning 401: 'AnObjectXXX' must be defined before it is used as a base class.

will give you a python object without expected baseclass functionality.

Sign up to request clarification or add additional context in comments.

Comments

2

You should get that without any further effort. Here's some documentation from http://www.swig.org/Doc1.3/Python.html#Python_nn21.

31.3.8 C++ inheritance

SWIG is fully aware of issues related to C++ inheritance. Therefore, if you have classes like this

class Foo {
...
};

class Bar : public Foo {
...
};

those classes are wrapped into a hierarchy of Python classes that reflect the same inheritance structure. All of the usual Python utility functions work normally:

1 Comment

That sounds comforting. Just does not work for me and I'm not sure why..:( I only get access to the public functions defined in Bar, and not public functions in Foo..?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.