1# mode: run 2# tag: cpp, werror 3 4cdef extern from "shapes.h" namespace "shapes": 5 cdef cppclass Shape: 6 float area() 7 8 cdef cppclass Circle(Shape): 9 int radius 10 Circle(int) 11 12 cdef cppclass Square(Shape): 13 Square(int) 14 15from cython cimport typeof 16 17from cython.operator cimport dereference as d 18from cython.operator cimport preincrement as incr 19from libcpp.vector cimport vector 20 21def test_reversed_vector_iteration(L): 22 """ 23 >>> test_reversed_vector_iteration([1,2,3]) 24 int: 3 25 int: 2 26 int: 1 27 int 28 """ 29 cdef vector[int] v = L 30 31 it = v.rbegin() 32 while it != v.rend(): 33 a = d(it) 34 incr(it) 35 print('%s: %s' % (typeof(a), a)) 36 print(typeof(a)) 37 38def test_derived_types(int size, bint round): 39 """ 40 >>> test_derived_types(5, True) 41 Shape * 42 >>> test_derived_types(5, False) 43 Shape * 44 """ 45 if round: 46 ptr = new Circle(size) 47 else: 48 ptr = new Square(size) 49 print typeof(ptr) 50 del ptr 51