Neil Fang | 20 Aug 04:40

Boost-users] [python]How to pass C++ object reference to python code?

I'm trying embedding python using boost::python. Just as the same way
as the boost::python quick start "embedding.cpp".
I have a C++ base class, with a virtual function do something on
another C++ object:
struct MyClass
{
	void printThis()
	{
		std::cout << "0x" << this << std::endl;
	}
};

// An abstract base class
class Base : public boost::noncopyable
{
public:
	virtual ~Base() {};
	virtual void printMyClass(MyClass& myObj) = 0;
};

Than, I want to write some Python derived class code:
"from embedded_hello import *        \n"
"class PythonDerived(Base):          \n"
"    def printMyClass(self, myObj):                \n"
"        myObj.printThis() \n"

But I found that the "myObj" passed to python code is another obj, not
the object created in C++ code. How can use the object created in C++
object rather than a copyed object? Thanks!

(Continue reading)

David Abrahams | 22 Aug 03:08
Favicon
Gravatar

Re: Boost-users] [python]How to pass C++ object reference to python code?


on Tue Aug 19 2008, "Neil Fang" <neilfang2009-AT-gmail.com> wrote:

> I'm trying embedding python using boost::python. Just as the same way
> as the boost::python quick start "embedding.cpp".
> I have a C++ base class, with a virtual function do something on
> another C++ object:
> struct MyClass
> {
> 	void printThis()
> 	{
> 		std::cout << "0x" << this << std::endl;
> 	}
> };
>
> // An abstract base class
> class Base : public boost::noncopyable
> {
> public:
> 	virtual ~Base() {};
> 	virtual void printMyClass(MyClass& myObj) = 0;
> };
>
> Than, I want to write some Python derived class code:
> "from embedded_hello import *        \n"
> "class PythonDerived(Base):          \n"
> "    def printMyClass(self, myObj):                \n"
> "        myObj.printThis() \n"
>
> But I found that the "myObj" passed to python code is another obj, not
(Continue reading)


Gmane