Calling C++ Parent / Base class Constructors #1581

scopatz opened this Issue Jan 17, 2017 · 0 comments


None yet

1 participant

scopatz commented Jan 17, 2017

There didn't seem to be an issue for this, but I wanted to capture this thread from the mailing list. Basically, cppclass cannot call the base class constructors. This is must for some libraries where "Base::Base(arg)" does cannot be called explicitly in the constructor body.

The example from the mailing list is below.

For the time being I have circumvented this via a small post-process scrip available here:


namespace mine {

struct myclass
	myclass(int a_, int b_);
	int a;
	int b;



//myclass::myclass() {}

myclass::myclass(int a_, int b_)
	this->a = a_;
	this->b = b_;


cdef extern from "myclass.hpp" namespace "mine":

        cdef cppclass myclass:
        myclass(int a_, int b_)
        int a
        int b


cimport cmyclass

cdef cppclass _myclass(cmyclass.myclass):
    __init__(PyObject* tup):
       # WOULD LIKE TO CALL myclass::myclass(int, int) HERE.

        this.a = int((<object>tup)[0])
        this.b = int((<object>tup)[1])

cdef class MyClass(object):

    cdef _myclass *thisptr

    def __cinit__(self):
        self.thisptr = new _myclass((5, 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment