[C++-sig] V2 runtime error

Peter Bienstman peter.bienstman at rug.ac.be
Fri Apr 5 00:11:54 CEST 2002


By popular demand, another problem report ;-)

This code gives a run time error:

RuntimeError: extension class wrapper for base class 3MWG has not been
created yet

The testcase is distilled from my code, but there, I don't get a runtime
error, but strange runtime results (for creation of subsequent P
objects, a bogus m object is used, which is always the same regardless
of the actual argument.) Not sure if it's the same problem, though.

Peter

#define BOOST_PYTHON_DYNAMIC_LIB
#define BOOST_PYTHON_V2

#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
#include <boost/mpl/type_list.hpp>

#include <iostream>
using namespace std;

struct BM {virtual void f() = 0;};
struct M : public BM {void f() {}};

struct WG {virtual void g() = 0;};
struct MWG : public WG {};
struct P : public MWG
{
    P(M& m_) : m(&m_) {cout << m << endl;}
    void g() {}
    M* m;
};


BOOST_PYTHON_MODULE_INIT(m)
{
  using namespace boost::python;
  using boost::mpl::type_list;
  

  module m("m");
  
  m
    .add(class_<BM, boost::noncopyable>("BM"))
    .add(class_<M, bases<BM> >("M"))
    .add(class_<WG, boost::noncopyable>("WG"))
    .add(class_<MWG, bases<WG>, boost::noncopyable >("MWG"))
    .add(class_<P, bases<MWG> >("P")
         .def_init(type_list<M&>()));
}









More information about the Cplusplus-sig mailing list