| Overloading

The following illustrates a scheme for manually wrapping an overloaded member functions. Of course, the same technique can be applied to wrapping overloaded non-member functions.

We have here our C++ class:

`

        struct X
        {
            bool f(int a)
            {
                return true;
            }

            bool f(int a, double b)
            {
                return true;
            }

            bool f(int a, double b, char c)
            {
                return true;
            }

            int f(int a, int b, int c)
            {
                return a + b + c;
            };
        };

`

Class X has 4 overloaded functions. We shall start by introducing some member function pointer variables:

`

        bool    (X::*fx1)(int)              = &X::f;
        bool    (X::*fx2)(int, double)      = &X::f;
        bool    (X::*fx3)(int, double, char)= &X::f;
        int     (X::*fx4)(int, int, int)    = &X::f;

`

With these in hand, we can proceed to define and wrap this for Python:

`

        .def("f", fx1)
        .def("f", fx2)
        .def("f", fx3)
        .def("f", fx4)

`

Copyright © 2002-2003 David Abrahams
Copyright © 2002-2003 Joel de Guzman
Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.