I have a class ClassA
implement interface IFooBar
like below
class ClassA : public Microsoft::WRL::RuntimeClass<IFooBar>
{
public:
virtual HRESULT RuntimeClassInitialize(ParamsForClassA);
}
Now I want to write a ClassB
inherent ClassA
and override it's RuntimeClassInitialize
function like below:
class ClassB : public ClassA
{
public:
HRESULT RuntimeClassInitialize(ParamsForClassB)
{
// implementation goes here
}
}
And I create a pointer to ClassB
object like this:
ComPtr<ClassB> ptr;
HRESULT hr = MakeAndInitialize<ClassB>(&ptr, ParamsForClassB);
But this actually goes to ClassA
's RuntimeClassInitialize
constructor. The ClassB
's RuntimeClassInitialize
code path is never hit.
I am wondering if this is the correct way of extending class in WRL? Where am I doing wrong in the code?
You need the overridden methods to have the same signature on both classes.
this
Can't be overridden by this
Because they take different arguments.
It's an overload, not an override. (And such overloads cause Name Hiding)
You can find info on signatures here or here.