[C++-sig] Can't get a simple example with fstream to compile & link

Stefan Seefeld seefeld at sympatico.ca
Wed May 21 21:35:52 CEST 2003


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





More information about the Cplusplus-sig mailing list