[C++-sig] boost.python: private copy constructor problem

Stefan Seefeld seefeld at sympatico.ca
Tue Dec 2 14:43:12 CET 2008


Mihail Konstantinov wrote:
> Hello,
> I am still in the early process of learning boost.python.
> I have reduced my problem to the following code:
>
> #include <boost/python.hpp>
> using namespace boost::python;
> class A{
> private:
>   A(const A&){}; //no public copy constructor
> };
> class B: public A{
> public:
>   B(){};
> };
> BOOST_PYTHON_MODULE(boost_ext)
> {
>     class_<A>("A",init<>());
>     class_<B, bases<A> >("B",init<>());
> }
>
> When running bjam on this example, I get
> "boost.cpp:6: error: ‘A::A(const A&)’ is private"
> as the first error among a long list of hints from the compiler.
>   


In this case you want to tell Python that your object is non-copyable:

class_<A, noncopyable> a("A", init<>);
...

See 
http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/class.html#class_-spec 
for details.

HTH,
       Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list