So I have a rather odd set of circumstances. I have one DLL that has a class defined with no interface, so it doesn't inherit from an abstract class with pure virtual functions. However I do know what those functions are like Vector GetVelocity() For the purpose of this question, assume that I cannot change the contents of the code of this DLL and that it's part of a larger project.
I have a second DLL in which it would be useful to be able to access functions from the aforementioned class. I can get a pointer to objects of this class as a void*, however, I cannot magically create an abstract interface class to do a reinterpret_cast.
It would look something like this IF I could:
virtual Vector GetVelocity() = 0;
So my question is, is there any way to create an interface to a class without it being inherited from? Could I abuse my void* in some way to get a pointer to a function in the class?
Any help is greatly appreciated. I'm just not quite sure if this is even possible.
To me, this means that your class (calling it class ActorA) has no public members and no associated free functions. But you seem to be using it differently, in that your class does not inherit from an abstract class, or maybe that it's not a part of an inheritance hierarchy. Correct me if I'm mistaken.
Is there any way to create an interface for a class without it being inherited from?
Yes. Ultimately, you need to handle multiple unrelated classes. As is common with this problem, you have two choices: either a. erase the type of the unrelated classes; or b. preserve the type of the unrelated classes in (e.g.) a discriminated union.