[C++-sig] Re: MEMBER_FUNCTION_OVERLOADS doesn't honor virtualness

David Abrahams dave at boost-consulting.com
Mon Nov 1 05:10:32 CET 2004


Jonathan Brandmeyer <jbrandmeyer at earthlink.net> writes:

> The subject says it all.  Attached is a test case.
>
> Thanks,
> -Jonathan Brandmeyer
>
>
>
> #include <boost/python.hpp>
> #include <iostream>
>
> class base
> {
>  public:
>     virtual void print_me(unsigned int i = 0)
>     {  std::cout << "base: " << i << "\n"; }
> };
>
> class derived : public base
> {
>  public:
>     void print_me( unsigned int i)
>     {  std::cout << "derived: " << i << "\n"; }
> };
>
> BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( print_me, base::print_me, 0, 1)
This won't compile without an ampersand-------------^

> BOOST_PYTHON_MODULE( idontwork)
> {
>     using namespace boost::python;
>     class_<base>("base")
>         .def( "print_me", &base::print_me, print_me())
>         ;
>
>     class_<derived, bases<base> >("derived")
>         ;
> }
>
>
> from idontwork import *
> x = base()
> y = derived()
>
> x.print_me()
> y.print_me()
> y.print_me(1)


What result are you expecting from this?  Can you rewrite the example
so that it asserts when you don't get the expected result.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com




More information about the Cplusplus-sig mailing list