[C++-sig] Typecasting

David Sveningsson ext at sidvind.com
Thu Dec 14 17:32:50 CET 2006


David Sveningsson skrev:
> Hi, I'm back again with another question. I am exposing some C++ classes
> to python using boost.
>
> A have a class that is exposed to python. The class has a virtual
> function that takes a pointer to a baseclass. This baseclass has a
> function that returns the type of the class. By looking at the type one
> can typecast into the corresponding class.
>
> Now, I want to expose this behavior to python. I have a wrapper class to
> expose the first class. It uses the get_override function to call the
> function in python. So far it works. I can instantiate the class in
> python and the method is called.
>
> The problem is what to do next. I can look at the type function and
> determine what type of class it is but whatever is passed into the
> function is always a baseclass in python. I need to convert the class
> into the right class.
>   
The biggest problem right now seems to be that when I call
"this->get_override("notify")(evt);" the instance is copied. Since it
refers to a Object baseclass thats what you get in python. But the
object class does not contain anything. Is there some way to call python
with a reference to the real instance?

-- 


//*David Sveningsson [eXt]*

Freelance coder | Game Development Student
http://sidvind.com

Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding.




More information about the Cplusplus-sig mailing list