[C++-sig] assign a pointer to global object
Roman Yakovenko
roman.yakovenko at gmail.com
Wed Jul 23 20:04:10 CEST 2008
On Wed, Jul 23, 2008 at 5:52 PM, Gennadiy Rozental <rogeeff at gmail.com> wrote:
> Hi,
>
> I am sure I missing something trivial, but I can't make work most simple example
> like this:
>
> c++ side
>
> struct AAA {
>
> };
>
> AAA s_global;
>
> void
> assign_aaa( bp::object& o )
> {
> o.attr("aaa") = &s_global;
> }
>
> ...
>
> export_func
> {
> ...
> class_<AAA,AAA*,boost::noncopyable>( "AAA", no_init );
>
> def( "assign_aaa", &assign_aaa );
> }
>
> python side:
>
> assign_aaa( object() )
>
> Error:
>
> TypeError: No to_python (by-value) converter found for C++ type: struct AAA
>
> Please advise,
Next code was generated by Py++:
#include "boost/python.hpp"
#include "1.h"
namespace bp = boost::python;
BOOST_PYTHON_MODULE(pyplusplus){
bp::class_< AAA, boost::noncopyable >( "AAA" )
.def( bp::init< >() );
bp::scope().attr("s_global") = bp::object( boost::ref( s_global ) );
}
HTH
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list