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

Mark Russell mrussell8081 at pacbell.net
Thu Nov 21 02:06:08 CET 2002


Sorry David,

The error message did not give me much of a hint on how to fix the problem.
I must admit I am struggling a bit with c++, BPL has for the most part made
the project I am working on very smooth going, most of the problems I am
running into are actually my own lack of c++ expertise.  BPL is certainly
the best wrapper lib I have ever worked with.  Thanks again for all your
help.  --Mark


-----Original Message-----
From: c++-sig-admin at python.org [mailto:c++-sig-admin at python.org]On
Behalf Of David Abrahams
Sent: Wednesday, November 20, 2002 4:14 PM
To: c++-sig at python.org
Subject: Re: [C++-sig] example in lvalue_from_pytype won't compile



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


_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig





More information about the Cplusplus-sig mailing list