[C++-sig] Virtual functions with default implementation.

Jacek Generowicz jacek.generowicz at cern.ch
Tue Dec 17 16:38:32 CET 2002


By copying and pasting the example code from

http://www.boost.org/libs/python/doc/tutorial/doc/class_virtual_functions.html

I constucted the following test program.

======================================================================
#include <boost/python.hpp>

using namespace boost::python;

struct Base
{
  virtual int f() { return 0; }
  virtual ~Base();
};

struct BaseWrap : Base
{
  BaseWrap(PyObject* self_)
    : self(self_) {}
  int f() { return call_method<int>(self, "f"); }
  static int default_f(Base* b) { return b->Base::f(); } // <<=== added
        PyObject* self;
};

BOOST_PYTHON_MODULE(virt)
{
  class_<Base, BaseWrap>("Base")
    .def("f", &BaseWrap::default_f)
    ;
}
======================================================================

This fails to compile (errors included below for completenes) with gcc
3.2 (and Boost 1.29).

Is it me, is it the docs, or something else ?

Thanks,

Jacek.



Tons of compiler output follows ...



In file included from /afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python.hpp:43,
                 from virtualboost.cc:1:
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:184:42: warning: pasting "operator" and "+" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:185:42: warning: pasting "operator" and "-" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:186:42: warning: pasting "operator" and "*" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:187:42: warning: pasting "operator" and "/" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:188:42: warning: pasting "operator" and "%" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:189:49: warning: pasting "operator" and "<<" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:190:49: warning: pasting "operator" and ">>" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:191:42: warning: pasting "operator" and "&" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:192:42: warning: pasting "operator" and "^" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:193:40: warning: pasting "operator" and "|" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:194:39: warning: pasting "operator" and ">" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:195:40: warning: pasting "operator" and ">=" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:196:39: warning: pasting "operator" and "<" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:197:40: warning: pasting "operator" and "<=" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:198:40: warning: pasting "operator" and "==" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:199:40: warning: pasting "operator" and "!=" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:271:38: warning: pasting "operator" and "+=" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:272:38: warning: pasting "operator" and "-=" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:273:38: warning: pasting "operator" and "*=" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:274:38: warning: pasting "operator" and "/=" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:275:38: warning: pasting "operator" and "%=" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:276:42: warning: pasting "operator" and "<<=" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:277:42: warning: pasting "operator" and ">>=" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:278:38: warning: pasting "operator" and "&=" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:279:38: warning: pasting "operator" and "^=" does not give a valid preprocessing token
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/operators.hpp:280:37: warning: pasting "operator" and "|=" does not give a valid preprocessing token
In file included from virtualboost.cc:1:
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python.hpp:62:8: warning: extra tokens at end of #endif directive
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/object/value_holder.hpp: In
   constructor `boost::python::objects::value_holder_back_reference<Held, 
   BackReferenceType>::value_holder_back_reference(PyObject*, A0) [with A0 = 
   boost::reference_wrapper<const Base>, Held = Base, BackReferenceType = 
   BaseWrap]':
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/object/make_instance.hpp:65:   instantiated from `static Holder* boost::python::objects::make_instance<T, Holder>::construct(boost::python::objects::instance<Holder>*, boost::reference_wrapper<const T>) [with T = Base, Holder = boost::python::objects::value_holder_back_reference<Base, BaseWrap>]'
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/object/make_instance.hpp:35:   instantiated from `static PyObject* boost::python::objects::make_instance<T, Holder>::execute(Arg&) [with Arg = const boost::reference_wrapper<const Base>, T = Base, Holder = boost::python::objects::value_holder_back_reference<Base, BaseWrap>]'
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/object/class_wrapper.hpp:23:   instantiated from `static PyObject* boost::python::objects::class_wrapper<Src, Holder, MakeInstance>::convert(const Src&) [with Src = Base, Holder = boost::python::objects::value_holder_back_reference<Base, BaseWrap>, MakeInstance = boost::python::objects::make_instance<Base, boost::python::objects::value_holder_back_reference<Base, BaseWrap> >]'
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/converter/to_python_function_type.hpp:24:   instantiated from `static PyObject* boost::python::converter::as_to_python_function<T, ToPython>::convert(const void*) [with T = Base, ToPython = boost::python::objects::class_wrapper<Base, boost::python::objects::value_holder_back_reference<Base, BaseWrap>, boost::python::objects::make_instance<Base, boost::python::objects::value_holder_back_reference<Base, BaseWrap> > >]'
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/to_python_converter.hpp:32:   instantiated from `boost::python::to_python_converter<T, Conversion>::to_python_converter() [with T = Base, Conversion = boost::python::objects::class_wrapper<Base, boost::python::objects::value_holder_back_reference<Base, BaseWrap>, boost::python::objects::make_instance<Base, boost::python::objects::value_holder_back_reference<Base, BaseWrap> > >]'
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/class.hpp:80:   instantiated from `void boost::python::detail::register_copy_constructor(const boost::mpl::bool_c<true>&, const SelectHolder&, T*) [with T = Base, SelectHolder = boost::python::objects::detail::select_value_holder<Base, BaseWrap>]'
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/class.hpp:422:   instantiated from `void boost::python::class_<T, X1, X2, X3>::register_() const [with T = Base, X1 = BaseWrap, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]'
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/class.hpp:432:   instantiated from `boost::python::class_<T, X1, X2, X3>::class_(const char*, const char*) [with T = Base, X1 = BaseWrap, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]'
virtualboost.cc:22:   instantiated from here
/afs/cern.ch/sw/lcg/external/Boost/1.29.0/rh73_gcc32/boost/python/object/value_holder.hpp:129: no
   matching function for call to `BaseWrap::BaseWrap(PyObject*&, const Base&)'
virtualboost.cc:12: candidates are: BaseWrap::BaseWrap(const BaseWrap&)
virtualboost.cc:14:                 BaseWrap::BaseWrap(PyObject*)






More information about the Cplusplus-sig mailing list