Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::python: compilation fails because copy constructor is private

Tags:

c++

python

i use boost::python to wrap a C++ class. This class does not allow copy constructors, but the python module always wants to create one.

The C++ class looks like this (simplified)

class Foo {
  public:
    Foo(const char *name); // constructor

  private:
    ByteArray m_bytearray;
};

The ByteArray class is inherited from boost::noncopyable, therefore Foo does not have copy constructors.

Here's the Python module stub:

BOOST_PYTHON_MODULE(Foo)
{   
  class_<Foo>("Foo", init<const char *>())
  ;
}

When compiling the boost::python module, i get errors that a copy constructor for Foo cannot be created because ByteArray inherits from boost::noncopyable.

How can i disable copy constructors in my python module?

Thanks Christoph

like image 722
cruppstahl Avatar asked Apr 13 '12 14:04

cruppstahl


1 Answers

I found it. i have to specify boost::noncopyable:

BOOST_PYTHON_MODULE(Foo)
{   
  class_<Foo, boost::noncopyable>("Foo", init<const char *>())
  ;
}
like image 108
cruppstahl Avatar answered Oct 02 '22 15:10

cruppstahl