[C++-sig] example in lvalue_from_pytype won't compile

David Abrahams dave at boost-consulting.com
Thu Nov 21 01:14:25 CET 2002


Mark, when posting errors, please make an effort to clearly indicate
the line where the error occurred. You probably would have been able
to figure out the problem and submit a patch if you had done this!

Mark Russell <mrussell8081 at pacbell.net> writes:

> I am working with the lvalue_from_pytype example and can't get it to
> compile.  My code and the errors are as follows:

This is a doc bug.

> #include <boost/python.hpp>
>
> //defines
> extern "C" _declspec(dllimport) PyTypeObject noddy_NoddyType;
> typedef struct {
>     PyObject_HEAD
> 	long magicNum;
> } noddy_NoddyObject;
>
> using namespace boost::python;
> static handle<> cache;
                ^--- need `noddy_NoddyObject' here.
>
> bool is_cached(noddy_NoddyObject* x)
> {
>    return x == cache.get();
> }
>
> void set_cache(noddy_NoddyObject* x)
> {
>    cache = handle<>(borrowed(x));
                    ^--- need `noddy_NoddyObject' here.
> }
>
> BOOST_PYTHON_MODULE(noddy_cache)
> {
>    def("is_cached", is_cached);
>    def("set_cache", set_cache);
>
>    // register Noddy lvalue converter
>
> lvalue_from_pytype<extract_identity<noddy_NoddyObject>,&noddy_NoddyType>();
> }
>
> Compiling...
> nc.cpp
> C:\developer\com-hacking\boost hacking\noddy cache\nc.cpp(15) : error C2446:
> '==' : no conversion from 'struct _object *' to 'noddy_NoddyObject *'
>         Types pointed to are unrelated; conversion requires
> reinterpret_cast, C-style cast or function-style cast
> C:\developer\com-hacking\boost hacking\noddy cache\nc.cpp(15) : error C2230:
> '==' : indirection to different types
> Error executing cl.exe.

-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list