My classes structure is like:
class MethodHelper : public QObject, public IMethodHelper {
public:
// Stuff
};
Now, I get a pointer to the object:
QObject* someObject = getMethodHelper();
Here, I am extremely sure that someObject
is a type of MethodHelper. I somehow want to cast it to IMethodHelper. How should I go about it?
My current thoughts are like QObject -> MethodHelper -> IMethodHelper
, like:
QObject* someObject = getMethodHelper();
MethodHelper* myHelper = qobject_cast<MethodHelper*>(someObject);
IMethodHelper* myIHelper = dynamic_cast<IMethodHelper*>(myHelper);
is there a potential flaw in my approach?
You could do it the way you present, but it isn't necessary. The Below should work fine.
IMethodHelper* myIHelper = dynamic_cast<IMethodHelper*>(someObject);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With