[C++-sig] Re: possible handle_exception_impl error

Mike Rovner mike at bindkey.com
Thu Nov 21 01:37:59 CET 2002


"David Abrahams" <dave at boost-consulting.com> wrote in message
news:u1y5fby1t.fsf at boost-consulting.com...
> "Mike Rovner" <mike at bindkey.com> writes:
>
> > I got a crash with following backtrace:
> >
> > Source:
> >
> > struct  X {
> >     X(const char* init) : name(init) {}
> >     const char* Name() { return name.c_str();}
> > private:
> >     std::string name;
> > };
> >
> > struct Obj : X { ... };
> >
> > class_<Obj>("Obj").add_property("name", (const char*
(Obj::*)())&Obj::Name);
>
> No module initialization function?

Oh well, excuse my laziness. :)

#include <boost/python.hpp>

using namespace boost::python;

namespace Tcn {
struct  X {
    X(const char* init) : name(init) {}
    const char* Name() { return name.c_str();}
private:
    const std::string name;
};
}
using namespace Tcn;

struct Obj : X {
  explicit Obj(const char* init) : X(init), other_data(0) {}
  int other_data;
};

BOOST_PYTHON_MODULE(PyTcn)
{
class_<Obj>("Obj", init<const char*>() )
.add_property("name", (const char* (Obj::*)())&Obj::Name);
}

The code above is working fine standalone, but crashes as part of bigger
module. :(
Apparently my namespace clashes with boost::python. :(








More information about the Cplusplus-sig mailing list