[C++-sig] wrapping virtual base class with std::auto_ptr

Faheem Mitha faheem at email.unc.edu
Tue May 3 00:50:51 CEST 2005


Hi,

Consider the following simple example. This works fine if (for
example) I replace std:auto_ptr<int> with int (see commented-put
lines). This also works if this is just a regular struct (if f is a
normal function returning a std::auto::ptr<int>).

The compiler errors I get appear below. The offending line is.

     return this->get_override("f")();

I have a dim understanding of how Boost.Python works in general, but
really don't understand what magic goes on in wrapping virtual
functions etc. I've just copied the syntax below from the tutorial.

Thanks in advance for help. Please cc me; I'm not subscribed.

                                                           Faheem.

ap.cc: In member function `virtual std::auto_ptr<int> BaseWrap::f(int)':
ap.cc:17: error: no matching function for call to `std::auto_ptr<int>::auto_ptr
    (std::auto_ptr<int>)'
/usr/include/c++/3.3/memory:334: error: candidates are:
    std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr_ref<_Tp>) [with _Tp = int]
/usr/include/c++/3.3/memory:204: error:
    std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp1>&) [with _Tp1 = int, _Tp =
    int]
/usr/include/c++/3.3/memory:192: error:
    std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp>&) [with _Tp = int]
ap.cc:17: error:   initializing temporary from result of `
    boost::python::detail::method_result::operator T() [with T =
    std::auto_ptr<int>]'
error: command 'gcc' failed with exit status 1

*********************************************************************
ap.cc
*********************************************************************
#include <boost/python.hpp>

using namespace boost::python;

struct Base
{
   virtual std::auto_ptr<int> f(int val) = 0;
   // virtual int f(int val) = 0;
};

struct BaseWrap : Base, wrapper<Base>
{
   BaseWrap():Base(){}
   std::auto_ptr<int> f(int val)
   // int f(int val)
   {
     return this->get_override("f")();
   }
};

BOOST_PYTHON_MODULE(ap)
{
   class_<BaseWrap, boost::noncopyable>("Base")
     .def("f", pure_virtual(&Base::f))
     ;
}
*********************************************************************



More information about the Cplusplus-sig mailing list