C++/WinRT implementation inheritance: Notes on winrt::implements, part 1
Summary
winrt::implements
is used for implementing interfaces in C++/WinRT.
- The general pattern for
winrt::implements
is to repeat the name of the derived type as the first template parameter.
- It uses the Curiously Recurring Template Pattern (CRTP) to access methods of the derived type.
- The "other stuff" in
winrt::implements
can include C++/WinRT interfaces, classic COM interfaces, C++/WinRT runtime classes, marker classes, and other interfaces (maximum 1).
- When implementing a C++/WinRT runtime class with multiple interfaces, only the first one is used, and the rest are ignored.
- It's recommended to use the autogenerated T-template for implementing a runtime class declared in an IDL file instead of
winrt::implements
.
Bonus Chatter
- Reading the C++/WinRT code and figuring it out can help you become an expert in implementing interfaces.
- Understanding how
winrt::implements
works can help in better structuring code and ensuring that all required interfaces are implemented.