microsoft / DirectXTK

The DirectX Tool Kit (aka DirectXTK) is a collection of helper classes for writing DirectX 11.x code in C++
https://walbourn.github.io/directxtk/
MIT License
2.57k stars 511 forks source link

"error C2259: 'ViewProviderFactory': cannot instantiate abstract class" after adding C++/WinRT package to UWP template project #175

Closed trojanfoe closed 5 years ago

trojanfoe commented 5 years ago

After adding Microsoft.Windows.CppWinRT package 2.0.190425.5 to the UWP template project I get the following compile errors:

1>d:\source\gameproj\gameproj\generated files\winrt\base.h(8945): error C3246: 'winrt::impl::heap_implements<D>': cannot inherit from 'ViewProvider' as it has been declared as 'final'
1>        with
1>        [
1>            D=ViewProvider
1>        ] (compiling source file Source\Main.cpp)
1>d:\source\gameproj\gameproj\source\main.cpp(20): note: see declaration of 'ViewProvider' (compiling source file Source\Main.cpp)
1>d:\source\gameproj\gameproj\generated files\winrt\base.h(2005): note: see reference to class template instantiation 'winrt::impl::heap_implements<D>' being compiled
1>        with
1>        [
1>            D=ViewProvider
1>        ] (compiling source file Source\Main.cpp)
1>d:\source\gameproj\gameproj\source\main.cpp(377): note: see reference to function template instantiation 'auto winrt::make<ViewProvider,>(void)' being compiled
1>d:\source\gameproj\gameproj\source\main.cpp(395): error C2259: 'ViewProviderFactory': cannot instantiate abstract class
1>d:\source\gameproj\gameproj\source\main.cpp(395): note: due to following members:
1>d:\source\gameproj\gameproj\source\main.cpp(395): note: 'void winrt::implements<ViewProviderFactory,winrt::Windows::ApplicationModel::Core::IFrameworkViewSource>::use_make_function_to_create_this_object(void)': is abstract
1>d:\source\gameproj\gameproj\generated files\winrt\base.h(9050): note: see declaration of 'winrt::implements<ViewProviderFactory,winrt::Windows::ApplicationModel::Core::IFrameworkViewSource>::use_make_function_to_create_this_object'

Prior to adding the package (and I assume using winrt headers in the Win 10 SDK) I did not get this error, however VS Intellisense didn't like the call to Run():

CoreApplication::Run(viewProviderFactory);

One of the errors can be solved by removing final from ViewProvider however I'm too much of an UWP/WinRT n00b to figure out the other error.

Visual Studio version 15.9.11 Windows 10 SDK 10.0.17763.0 Project target platform 10.0.17763.0 Project min platform 10.0.15063.0

trojanfoe commented 5 years ago

Note that this issue is really against the DirectXTK VS templates, not the DirectXTK library itself, so sorry about that.

Here is the solution:

IFrameworkViewSource viewProviderFactory = winrt::make<ViewProviderFactory>();
CoreApplication::Run(viewProviderFactory);
walbourn commented 5 years ago

Ah, this should be tracked here then.

Note that the Microsoft.Windows.CppWinRT doesn't include the C++/WinRT version of the headers... they are part of the Windows 10 SDK (17763). It just provides the debugging support and cppwinrt complier if you want to convert your own winmd files. I'm guessing the problem here is then with the new 'generated base.h'...

walbourn commented 5 years ago

Thanks again for the report. Looks like that change supports existing C++/WinRT base.h as well as that newly generated one, which is good news.

Fixed in this commit.