Search code examples
c++-winrt

Inheritance in C++/WinRT Windows Runtime Components


I have a couple of questions related to inheritance in Windows Runtime Components authored using C++/WinRT. Firstly why is there a restriction that classes, if they have a base class, must have ultimately derive from a class in the Windows.* namespace?

Secondly, what is the best way to work around this. In fact I don't really want consumers to be able to derive from my class, but I'd like to derive from a base class in the implementation in order not to rewrite code. At the moment my implementation class is a lightweight wrapper around a standard C++ class that uses standard C++ inheritance. But is there a way to simplify this? Can a list one implementation class as the base class of another? I am mainly familiar with C# where multiple inheritance is not possible, so am not sure about this sort of thing.


Solution

  • Any runtime class (that you declare in your application) that derives from a base class is known as a composable class. The ultimate base class of a composable class must be a type originating in a Windows.* namespace;.

    And if you want to inherit custom runtimeclass, the Windows App Certification Kit tests will produce errors. From this thread, it seems that you can only declare a C++ native class and implement the interfaces. Let the implementation classes inherit from it.