How does Microsoft::WRL::ComPtr do the type conversion

99 Views Asked by At

I am getting an error for the following code:

struct __declspec(uuid("9DAD7B57-D626-4AB6-B844-910DE46DAC01")) IHen : public IUnknown
{
    virtual void Cluck() = 0;
};

struct __declspec(uuid("8FEA0426-91CA-4264-AAC5-544A7544E628")) IHen2 : IHen
{
    virtual void __stdcall Forage() = 0;
};

struct Hen : RuntimeClass<RuntimeClassFlags<ClassicCom>,
    IHen,
    IHen2>
{
    Hen(){}
    ~Hen(){}

    void Cluck() {}
    void Forage() {}
};

int main()
{
    ComPtr<IHen> hen;
    hen = Make<Hen>();
}

Error C2440 '': cannot convert from 'Microsoft::WRL::ComPtr<Hen>' to 'Microsoft::WRL::ComPtr<IHen>

If I change the ComPtr to:

ComPtr<IHen2> hen;

It works.

I am trying to understand why. How can it convert to immediate base, but not to its base?

0

There are 0 best solutions below