[C++-sig] Re: Boost: virtual inheritance

David Abrahams dave at boost-consulting.com
Mon Sep 15 23:05:48 CEST 2003


Jacek Generowicz <jacek.generowicz at cern.ch> writes:

> Thanks for your quick response (unfortunately I was away last week, so
> we were not able to continue this work for a while).
>
> This allows us to proceed a bit further, however when we make
> Item::name return a _reference_ to std::string, it all goes wrong
> again; firstly, we are (quite rightly) asked to specify a return
> policy. Complying with the request, we are faced with the following error:
>
> /afs/cern.ch/sw/lcg/external/Boost/1.30.2/rh73_gcc32/boost/python/class.hpp:383: `sizeof'
>    applied to incomplete type `boost::STATIC_ASSERTION_FAILURE<false>'
>
> (Full error message included at the bottom, for completeness,
> once again.)
>
> Here's our (updated) minimal test case:
>
> ====================================================================
> #include <string>
>
> struct Item {
>   std::string m_name;
>   Item(const std::string& name):m_name(name) {}
>   const std::string& name() const { return m_name; }
>   virtual ~Item() {};
> };
>
> struct Class :  virtual public Item {
>   Class():Item("hello"){}
> };
>
>
> #include <boost/python.hpp>
> using namespace boost::python;
>
> BOOST_PYTHON_MODULE( btry ) {
>
>
>   class_<Item>("Item", no_init);
>     
>   class_<Class, bases<Item> >("Class")
>   .def("name", object(&Class::name), return_value_policy<copy_const_reference>());
> }
> ====================================================================
>
>> This problem is now fixed in CVS.
>
> Great. As we must present our work on our centrally installed version
> of Boost (currently 1.30.2), we can't really take advantage of this
> yet. If you believe that all our problems will go away by using the
> CVS version, then say the word, and we'll find sufficient motivation
> to install a (locally) non-standard version ... otherwise we'll keep
> trying to use workarounds, for now.

you need to pass 

        make_function(&Class::name, return_value_policy<copy_const_reference>())

instead.  The static assertion is telling you that the policies are
already determined once you write 

        object(&Class::name)

Of course, with the CVS version you don't need to do either of these
things.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list