Boost logo

Boost :

From: Anton Gluck (gluc_at_[hidden])
Date: 2000-10-24 23:03:56


Dave,

> It has nothing to do with CVar. The py::ClassWrapper<> constructor takes two
> parameters. One should be the module object.

Ah, now I see it - I had thought the "hello" in the example was the C++
namespace, when it was the module name. As usual, your comments cleared it
all up.

And also as usual, I ran into yet another prolem: I am trying to wrap a
class that takes a reference to an ifstream as parameter. This is the C++
code for the constructor:

TextRecordIterator::TextRecordIterator(std::ifstream& inputData) :
fDataFile(inputData) {}

This is how I tried to wrap it:

TextRecordIterator_class.def(py::Constructor<std::ifstream&>());

And these are the errors:

d:\py_cpp/init_function.h(91) : error C2665: 'from_python' : none of the
112 overloads can convert parameter 2 from type 'struct py::Type<class
std::basic_ifstream<char,struct std::char_traits<char> > &>'
        d:\py_cpp/init_function.h(86) : while compiling class-template
member function 'class py::InstanceHolderBase *__thiscall py::Init1<class
py::InstanceValueHolder<class TextRecordIterator,class
py::HeldInstance<class TextRecordIterator> >,class
std::basic_ifstream<char,struct std::char_traits<char> >
&>::create_holder(class py::ExtensionInstance *,struct _object *,struct
_object *) const'
d:\py_cpp/init_function.h(92) : error C2661: 'InstanceValueHolder<class
TextRecordIterator,class py::HeldInstance<class TextRecordIterator>
>::InstanceValueHolder<class TextRecordIterator,class
py::HeldInstance<class TextRecordIterator> >' : no over
loaded function takes 2 parameters
        d:\py_cpp/init_function.h(86) : while compiling class-template
member function 'class py::InstanceHolderBase *__thiscall py::Init1<class
py::InstanceValueHolder<class TextRecordIterator,class
py::HeldInstance<class TextRecordIterator> >,class std::basic_ifstream<char,struct std::char_traits<char> >
&>::create_holder(class py::ExtensionInstance *,struct _object *,struct
_object *) const'

I guess the problem here is that I/O streams are defined as templates with
char_type and char_traits. And I guess the solution to this is similar to
the one for enumeration - to write a special from_python. But since the
reference to the ifstream is what comes from Python but is not what's
defining char_type and char_trail, I can't see how to do this. Can you
help once again?

Many thanks,

Toni


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk