[C++-sig] VC7 + auto_ptr + transfer of owership

Nicolas Lelong n_lelong at hotmail.com
Fri Nov 22 18:35:00 CET 2002


Hi everyone,

whenever I try to declare a scheme of transfer of ownership to BP2, I get a
nasty compiler error.

I tries with a simple example, and it justs does the same. Here are my
simple classes:

struct Data
{
};

class Test
{
  std::auto_ptr<Data> m_data;
public:
  Test() {};
  Test(Test const& src) : m_data( src.m_data.get()==NULL ? NULL : new
Data(*src.m_data) ) {};

  void setData(std::auto_ptr<Data> data)
  {
    m_data = data;
  }
};

They are declared as follow :

BOOST_PYTHON_MODULE( mgd )
{
python::class_<Data> Data_class("Data");
python::class_<Test> Test_class("Test");
Test_class.def("setData", &Test::setData);
}

And my dear old VC7 tells me:

d:\Sources\mgd\include\boost\python\detail\returning.hpp(205) : error C2664:
'boost::python::detail::returning<R>::R (A0)' : cannot convert parameter 1
from 'const boost::add_const<T>::type' to 'std::auto_ptr<_Ty>'
with
[
R=void,
A0=std::auto_ptr<`anonymous-namespace'::Data>
]
and
[
T=std::auto_ptr<`anonymous-namespace'::Data>
]
and
[
_Ty=`anonymous-namespace'::Data
]
No copy constructor available for class 'std::auto_ptr<_Ty>' or constructor
attempts to perform illegal conversion to non-__gc reference
with
[
_Ty=`anonymous-namespace'::Data
]

Being curious, I followed an example I found in a previous post, and changed
the Holder for Data to auto_ptr, like this :

python::class_<Data, std::auto_ptr<Data> > Data_class("Data");

But when I do that, I grab another compiler error :

d:\Sources\mgd\include\boost\python\object\make_instance.hpp(60) : error
C2664: 'std::auto_ptr<_Ty>::auto_ptr(std::auto_ptr<_Ty> &)' : cannot convert
parameter 1 from 'const boost::python::class_<T,X1,X2,X3>::held_type' to
'std::auto_ptr<_Ty> &'
with
[
_Ty=`anonymous-namespace'::Data
]
and
[
T=`anonymous-namespace'::Data,
X1=std::auto_ptr<`anonymous-namespace'::Data>,
X2=boost::python::detail::not_specified,
X3=boost::python::detail::not_specified
]
and
[
_Ty=`anonymous-namespace'::Data
]
Conversion loses qualifiers

Am I doing something wrong ? Did anyone encounter this kind of problem ?

Thanks,
Nicolas.




More information about the Cplusplus-sig mailing list