Java loses object type when passed from C++ callback

View: New views
1 Messages — Rating Filter:   Alert me  

Java loses object type when passed from C++ callback

by Peter Cooner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've extended the the Swig Java example (
https://swig.svn.sourceforge.net/svnroot/swig/trunk/Examples/java/callback/
) to pass a C++ class object (which gets wrapped) to the Java callback
class, the Java is loosing the type of the C++ class if its been
extended.

Example:

class Parent {
  virtual const char* getName() { return typeid(*this).name(); }
}
class Child : virtual public Parent {}

bash$ java -Djava.library.path=. runme
Adding and calling a normal C++ callback
----------------------------------------
Callback::run(5Child)
Callback::~Callback()

Adding and calling a Java callback
------------------------------------
JavaCallback.run(Parent)
Callback::run(5Child)
Callback::~Callback()


I expect that the the type of the Java object to be Child - but it
isn't for some reason.

I've got the question posted online w/ source here
http://stackoverflow.com/questions/1077387/swig-c-w-java-loosese-type-on-polymorphic-callback-functions

I'm running SWIG Version 1.3.33 Compiled with g++ [i686-pc-linux-gnu]
on Ubuntu 8.04.. I'm currently compiling the latest SWIG in case its a
bug but I'm hoping this is something I'm doing wrong...

Any thoughts would be greatly appreciated.


Pete

------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user