C++ polymorphic objects

3 posts / 0 new
Last post
Offline
Last seen: 6 years 5 months ago
Joined: 09/17/2015
Posts: 53
C++ polymorphic objects

Hello all,

I modified the rtiddsgen templates in a way so that I can use unions as storage for polymorphic objects.

To be able to do that I added every IDL C++ class a virtual dummy function to be able to use dynamic cast on these. But this causes RTI to segfault when reciving data. I assume that RTI does access directly the memory and because the memory layout of virtual objects is different to the memory layout of non virtual objects.

Is there a way to solve this?

Best regards,

Andreas

Gerardo Pardo's picture
Offline
Last seen: 3 weeks 2 days ago
Joined: 06/02/2010
Posts: 601

Hello,

Yes the code that we generate assumes that there are no virtual methods in the classes.  I do not recall exactly why we introduced that limitation. I think it helps simplify some of the ContentFilterTopic and dynamic data algorithms that can use the same code for C and C++ types. This is an unfortunate side-effect. 

I will file an internal issue to take evaluate if this constraint could be removed in future releases...

Gerardo

Offline
Last seen: 6 years 5 months ago
Joined: 09/17/2015
Posts: 53

That is very unfortunate. One could implement polymorphism pretty nicely if this would be possible. With a little bit autogenerated idl code even fully automatic.

Now I have to use boost::variant which is much less nice.