Commit 05c79eaf authored by empyrical's avatar empyrical

Allow C++ class methods to use base class' methods

parent 2c3c04b2
......@@ -6302,7 +6302,7 @@ class AttributeNode(ExprNode):
# as an ordinary function.
if entry.func_cname and not hasattr(entry.type, 'op_arg_struct'):
cname = entry.func_cname
if entry.type.is_static_method:
if entry.type.is_static_method or env.parent_scope.is_cpp_class_scope:
ctype = entry.type
elif type.is_cpp_class:
error(self.pos, "%s not a static member of %s" % (entry.name, type))
......
......@@ -5,6 +5,7 @@
cdef double pi
from math import pi
from libc.math cimport sin, cos
from libcpp cimport bool
cdef extern from "shapes.h" namespace "shapes":
cdef cppclass Shape:
......@@ -42,6 +43,35 @@ def test_Poly(int n, float radius=1):
finally:
del poly
cdef cppclass BaseClass:
int n
int method():
return this.n
cdef cppclass SubClass(BaseClass):
bool override
__init__(bool override):
this.n = 1
this.override = override
int method():
if override:
return 0
else:
return BaseClass.method()
def test_BaseMethods(x):
"""
>>> test_BaseMethods(True)
0
>>> test_BaseMethods(False)
1
"""
cdef SubClass* subClass
try:
subClass = new SubClass(x)
return subClass.method()
finally:
del subClass
cdef cppclass WithStatic:
@staticmethod
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment