Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-10-18 16:59:26


Lyle,

Good question. The answer is (somewhat buried) in the documentation.
under-the-hood.html reads:

"Because the to_python and from_python functions for a user-defined class
are defined by ExtensionClass<T>, it is important that an instantiation of
ExtensionClass<T> is visible to any code which wraps a C++ function with a
T, T*, const T&, etc. parameter or return value. In particular, you may want
to create all of the classes at the top of your module's init function, then
def the member functions later to avoid problems with inter-class
dependencies"

At the point where you want to invoke call_method(), the to_python()
conversion function for FXStream must already be visible. That can only
happen if py::ClassWrapper<FXStream,...> or py::ExtensionClass<FXStream,...>
is declared before this save function is defined. The simplest fix would be
to try moving the /definition/ of save() to the end of the translation unit.

You can also try explicitly instantiating:
  py::ExtensionClass<FXStream>;
at some point before the definition of save(), if you don't want to move
save().

-Dave
----- Original Message -----
From: "Lyle Johnson" <ljohnson_at_[hidden]>

> David,
>
> I've just started playing around with py_cpp to see if it could be used
with
> FXPy. Is it expected that when I invoke call_method() where one of the
> arguments is a const reference to one of my classes (i.e. not a pointer,
and
> not a primitive type) that this won't compile? The offending function
looks
> like this:
>
> virtual void save(FXStream& store) const {
> py::Callback<void>::call_method(m_self, "save", store);
> }
>
> and the compiler (Microsoft Visual C++ 6.0) chokes with this output:
>
> cl /GR
> /GX -I.. -I../fox-0.99.135/include -I../boost_1_18_1 -IC:/Python20/include
> /c example1.cpp
> Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
> Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
>
> example1.cpp
> ..\py_cpp/callback.h(61) : error C2665: 'to_python' : none of the 20
> overloads can convert parameter 1 from type 'const class FXStream'
> example1.cpp(29) : see reference to function template
instantiation
> 'void __cdecl py::Callback<void>::call_method(struct _object *,const char
> *,const class FXStream &)' being compiled
> make: *** [example1.obj] Error 2
>
> Lyle
>


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