I have a class with implements 2 interfaces and inherits 1 class. So, generally it looks like this:
class T : public A, public IB, public IC {
};
There is one point in the code where I have an "IB *", but could really use an "A *". I was hoping that a dynamic cast would like this:
IB *b_ptr = new T; // it's really more complicated, but serves the example
A *a_ptr = dynamic_cast<A *>(b_ptr);
unfortunately, this doesn't work. Is there a proper way to do this? Or should I implement a work around? I've thought about having both IB and IC inherit virtually from A, but IIRC last time I tried that there were some complications that made it undesirable.
Any thoughts?
EDIT: oh yea, this is part of a plugin API, so unfortunately I don't have direct access to the T type where I need the "A *". My example has then next to each other, but as mentioned, it's more complicated. Basically I have 2 shared libraries. T and T1 (where I have an IB *) are both classes which implement a plugin API and are internal to the shared libraries.
To clarify: Here's a more specific example of my typical plugins (they are in separate libraries):
plugin A:
class PluginA : public QObject, public PluginInterface, public OtherInterface {
};
plugin B:
class PluginB : public QObject, public PluginInterface {
// in here, I have a PluginInterface *, but really could use a QObject *
// unfortunately, PluginB has absolutely no knowledge of the "PluginA" type
// it just so happens that my PluginInterface * pointer points to an object of type
// PluginA.
};
EDIT: I have a guess that the issue is that pluginA and pluginB are in different shared libraries. Perhaps the rtti doesn't cross module boundaries. I think this might be the case because people's examples seem to work fine in my tests. Specifically, pluginB has no "typeinfo for PluginA" if I do an "nm" on it. This may be the core of the issue. If this is the case, I'll simply have to work around it by either virtual inheritance or a virtual "cast_to_qobject" function in one of my interfaces.