Skip to content

Binding members within class inheritance #3842

Answered by jiwaszki
MarAlder asked this question in Q&A
Discussion options

You must be logged in to vote

In fact your code is OK, there is a problem with C++ base provided by you. Remove virtual ~Vector(){} from your class and keep bindings as is. Actually if you inherit class -- it also reflects this in Python. Here, you may see that after calling to dir(Vector) it shows both methods and use vectorBase as self:

In [2]: import mymodule

In [3]: a = mymodule.Vector()

In [4]: a.size()
Out[4]: 3

In [5]: a.values()
Out[5]: [1.0, 2.0, 3.0]

In [6]: dir(mymodule.Vector)
Out[6]: 
['__class__',
 '__delattr__',
 '__dir__',
# ...
 '__subclasshook__',
 'size',
 'values']
 
 In[7]: help(my module.Vector.size)
 Help on instancemethod in module mymodule:

size(...)
    size(self: mymodule.vectorBase) -> i…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MarAlder
Comment options

Answer selected by MarAlder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants