Commit 2be549d8 authored by Robert Bradshaw's avatar Robert Bradshaw

Cleanup of C++ docs.

parent 5c3fb00a
...@@ -312,30 +312,34 @@ and use any of them:: ...@@ -312,30 +312,34 @@ and use any of them::
Overloading operators Overloading operators
---------------------- ----------------------
Cython uses C++ for overloading operators:: Cython uses C++ naming for overloading operators::
cdef extern from "foo.h": cdef extern from "foo.h":
cdef cppclass Foo: cdef cppclass Foo:
Foo() Foo()
Foo* operator+(Foo*) Foo operator+(Foo)
Foo* operator-(Foo) Foo operator-(Foo)
int operator*(Foo*) int operator*(Foo)
int operator/(int) int operator/(int)
cdef Foo* foo = new Foo() cdef Foo foo = new Foo()
cdef int x
cdef Foo* foo2 = foo[0] + foo foo2 = foo + foo
foo2 = foo[0] - foo[0] foo2 = foo - foo
x = foo[0] * foo2 x = foo * foo2
x = foo[0] / 1 x = foo / 1
cdef Foo f Note that if one has *pointers* to C++ objects, dereferencing must be done
foo = f + &f to avoid doing pointer arithmetic rather than arithmetic on the objects
foo2 = f - f themselves::
cdef Foo* foo_ptr = new Foo()
foo = foo_ptr[0] + foo_ptr[0]
x = foo_ptr[0] / 2
del foo_ptr
del foo, foo2
Nested class declarations Nested class declarations
-------------------------- --------------------------
......
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