walbourn / directx-vs-templates

Direct3D Visual Studio Templates
https://walbourn.github.io/direct3d-game-visual-studio-templates-redux/
MIT License
412 stars 56 forks source link

C++/WinRT Main.cpp is no longer compatible with latest base.h #23

Closed walbourn closed 5 years ago

walbourn 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

Originally reported here

walbourn commented 5 years ago

The solution provided by trojanfoe is thankfully easy and still compatible with older versions of C++/WinRT base.h:

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

Fixed in this commit.