5.4.1 Aliases for Overloading (or other purposes)

Cython doesn't support overloaded functions, but C++ libraries readily use this feature. Cython does provide a very simple way to alias these functions which we illustrate with an example borrowed from the NTL wrapper code.

cdef extern from "ntl_wrap.h":
    # really, this is from NTL/ZZ.h
    ctypedef struct ZZ_c "struct ZZ":
        pass
    void ZZ_add "add"( ZZ_c x, ZZ_c a, ZZ_c b)

    #### ZZ_p_c
    ctypedef struct ZZ_p_c "struct ZZ_p":
        pass
    void ZZ_p_add "add"( ZZ_p_c x, ZZ_p_c a, ZZ_p_c b)

Notice that NTL supports the add function for all of its many types. We rename them for use in Cython as <Type>_add where <Type> is the NTL type name of the objects being added.

Another type of aliasing in that example is the structure ZZ is called ZZ_c. We did this simply to alleviate confusion with the Sage integer class commonly known as ZZ. This trick is also useful if you have a C++ library that uses namespaces. (Actually NTL does use namespaces, but we were lazy and instead inserted a using namespaces NTL; in a header file).

See About this document... for information on suggesting changes.