Jump to content
  • Advertisement
Sign in to follow this  
nbertoa

Unity Polymorphism C++/Python

This topic is 2894 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi community.

I can use Boost::Python and SWIG to wrap classes from C++ to Python and vice versa.

Now I need information on the following:

Suppose I have the following class in C++:

class Base{

public:

virtual void Print();

};



The function Print() prints the class name, in this case, "Base".

Now suppose that I wrap the Base class for use in Python. Now, in Python, I write the class Derived that inherits from the wrapped Base class. The class Derived overwrites Print(), now prints "Derived".

Now, I wrap the class Derived from Python to C++.

The key question is: Can I use the wrapper class Derived polymorphically?[font="arial, sans-serif"] [/font]

Will be possible to do the following in C++?:
[font="arial, sans-serif"] [/font][font="arial, sans-serif"] [/font]
Base* pBase = new WrappedDerived();
pBase->Print();


and get "Derived"?[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"]
[/font]
[font="arial, sans-serif"] [/font]

Share this post


Link to post
Share on other sites
Advertisement
I don't use SWIG, but with boost::python, if you follow all the relevant instructions for binding your class with virtual functions then calling virtual member functions on derived classes implemented in Python should work like you expect.

Share this post


Link to post
Share on other sites

I don't use SWIG, but with boost::python, if you follow all the relevant instructions for binding your class with virtual functions then calling virtual member functions on derived classes implemented in Python should work like you expect.


Thanks for the info. So, all the Base class functions must be virtual??

Do you know where can I get a good tutorial about boost::python than its main site???


Share this post


Link to post
Share on other sites
No, base class member functions only need to be virtual if you want them to actual virtually. This is the same deal as normal class design in C++.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!