Problems in binding an abstract c++ class in python


I am trying to bind an abstract class in python with PyCintex, but get errors.

here is my C++ code

class base {
        base(int i = 0):m_int(i){}
        void SetMyInt(int i) { m_int = i;}
        virtual int GetMyInt() = 0;
        int m_int;

then genreflex… then g++…
in python scrpt

import PyCintex

class m_base(PyCintex.gbl.base):
    def __init__(self, m): 
        super(m_base, self).__init__(m)

    def GetMyInt(self):
        return super(m_base, self).m_int

m_obj = m_base(9)
print m_obj.GetMyInt()

[color=#FF0040]TypeError: base is abstract and can not be instantiated[/color]

Is there a way to use the abstract class in python without changing the C++ code?


what is the goal? Cross-language derivation does not work w/o an intermediate class (i.e. the GetMyInt() method will not be overridden in the example as you show it here; and the instantiated class, if it were to be made possible, could not be used).


Hi, wlav

I want to write a base class in C++, so that I can write an instantiated class in python. if not possible, I have to write the instantiated class in C++, and then call it in python.

Thank you for your reply.


for C++ to call the derived class, a vtable entry needs to exist, so the C++ compiler needs to fill that. Normally, this is done by writing a forwarding class in C++ (see e.g. TPySelector and the various fitter base classes). It’s not automatically possible at this point in time (I prototyped this with ACLiC, which was a bit of a kludge; it should be easy with Cling).