wrapping class with pure virtual function & non-default constructor
Hi, Please consider the following variation of the example in the tutorial. The main difference here is that the class that is being wrapped has a non-default destructor. Without a destructor declared in BaseWrap, this gives the error error: base `World' with only non-default constructor in class without a constructor Adding a default constructor to the wrapper class makes the error go away, eg. BaseWrap():Base(0){} I can't find an example of this anywhere. I've looked at the docs, but don't understand what is going on well enough. So, I'm asking here. Is this Ok, and can I use any default constructor for the wrapper class without it making any difference? One other thing. Am I correct in thinking that wrapping the base class in this fashion is necessary if I want to wrap the derived classes? Clarifications appreciated. I'm not subscribed, so please cc me at faheem@email.unc.edu if possible. Thanks. Faheem. ************************************************************************* #include <boost/python.hpp> #include <boost/python/module.hpp> #include <boost/python/class.hpp> #include <boost/python/return_value_policy.hpp> #include <boost/python/manage_new_object.hpp> #include <boost/python/reference_existing_object.hpp> #include <boost/python/pure_virtual.hpp> #include <boost/python/wrapper.hpp> #include <boost/python/def.hpp> #include <boost/python/call.hpp> #include <boost/utility.hpp> #include <iostream> #include <string> using namespace boost::python; struct Base { int data; Base(int _data):data(_data){} virtual ~Base() {} virtual int f() = 0; }; struct BaseWrap : Base, wrapper<Base> { BaseWrap():Base(0){} int f() { return this->get_override("f")(); } }; BOOST_PYTHON_MODULE_INIT(polymorphism2_ext) { class_<BaseWrap, boost::noncopyable>("Base") .def("f", pure_virtual(&Base::f)) ; }
Faheem Mitha <faheem@email.unc.edu> writes:
Hi,
Please consider the following variation of the example in the tutorial. The main difference here is that the class that is being wrapped has a non-default destructor.
Without a destructor declared in BaseWrap, this gives the error
error: base `World' with only non-default constructor in class without a constructor
Surely not. Where could the identifier `World' possibly come from in that code? The code compiles for me. I don't think what the error is talking about is really an error in C++, anyway. Are you using -Wall to turn warnings into errors?
Adding a default constructor to the wrapper class makes the error go away, eg.
BaseWrap():Base(0){}
I can't find an example of this anywhere. I've looked at the docs, but don't understand what is going on well enough. So, I'm asking here. Is this Ok, and can I use any default constructor for the wrapper class without it making any difference?
The answer to your problem, whatever it may be, doesn't really have anything to do with Boost.Python.
One other thing. Am I correct in thinking that wrapping the base class in this fashion is necessary if I want to wrap the derived classes?
No, it's not.
Clarifications appreciated. I'm not subscribed, so please cc me at faheem@email.unc.edu if possible.
Thanks. Faheem.
<snip code not containing the identifier `World' anywhere> -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams -
Faheem Mitha