logo       

Re: Can't get a simple example with fstream to compile & link: msg#00135

python.c++

Subject: Re: Can't get a simple example with fstream to compile & link

Fast Bike wrote:
I have been trying this for a little while. I can do
simple examples, but when I try to do something a
little more complex I get litany of errors.

For example creating a simple class that uses an
instance of fstream seems to give me trouble.

Example:
class PythonWrapper
{
public:
PythonWrapper(int id) : { myid = id; };

this is syntactically incorrect: you provide ':' but an empty
initializer list. That should read:

PythonWrapper(int id) : myid(id) {}

private:
int myid;
std::fstream myfile;
};

BOOST_PYTHON_MODULE(PythonWrapper)
{
using namespace boost::python;

scope x_class =
class_<PythonWrapper>("PythonWrapper",
init<int>())

;
}

the error hints at a problem with the copy constructor. May be the
class_ template requires a copy constructor to be present, but you
don't provide one, and the default (compiler generated) may just
not work, for example because std::fstream is neither copyable nor
assignable.

Regards,
Stefan


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise