[C++-sig] Static functions in Boost.Python

Mike Wyatt mwyatt at wi.rr.com
Fri May 19 04:44:04 CEST 2006


How can I define my C++ class' static functions in Boost.Python?  I 
googled the subject quite a bit, and failed to find anything useful, 
except for this little mailing between chuzo okada and Dave:

http://mail.python.org/pipermail/c++-sig/2002-July/001635.html

My guess is that this is not supported, since Python has no concept of 
static methods (right?).  If that is the case, should I simply declare 
"global" functions that use my Matrix class, and bind them in the 
BOOST_PYTHON_MODULE(matrix) block?

Here is an excerpt of my Matrix class and Boost.Python mapping:

class Matrix
{
public:
    /* other member functions */
    static Matrix* Translation(float x, float y, float z);
private:
    /* private variables */
}

BOOST_PYTHON_MODULE(matrix)
{
    class_<Matrix>("Matrix")
        /* other*/
        .def("Translation", &Matrix::Translation)
    ;
}

Thanks,

Mike

<http://mail.python.org/pipermail/c++-sig/2002-July/001635.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060518/8aeadd45/attachment.htm>


More information about the Cplusplus-sig mailing list