MicrosoftDocs / windows-dev-docs

Conceptual and overview content for developing Windows apps
Creative Commons Attribution 4.0 International
691 stars 1.2k forks source link

Compiler errors using winrt::make<> #849

Closed schlzber closed 6 years ago

schlzber commented 6 years ago

When I use the apropriate call to winrt::make<> in the constructor of my class I get compiler errors (translated from German):

musiclibrary.cpp(10): error C2672: "winrt::make": no matching overloaded function found musiclibrary.cpp(10): error C2974: "winrt::make": invalid template argument for "D", Type expected. 1>c:\program files (x86)\windows kits\10\include\10.0.17713.0\cppwinrt\winrt\base.h(8501): note: See declaration of "winrt::make"

The line in my code is this:

m_Artists = winrt::make<single_threaded_observable_vector<Windows::Foundation::IInspectable>>();

And m_Artists is defined like this: public: IVector<IInspectable> Artists(); private: IVector<IInspectable> m_Artists;

and in IDL:

    Windows.Foundation.Collections.IVector&lt;IInspectable&gt; Artists{ get; };

Any ideas what I'm missing?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

stevewhims commented 6 years ago

Hi, @schlzber, thanks for opening this issue: it looks like I need to improve this topic. winrt::make is expecting D to be a type; and the compiler error you're seeing can happen when you supply an identifier or a function as D, instead of a type. Are you using the released version of the SDK (which is 17134), or are you using a later Insider version of the SDK (version 17661 or later)? If you're using 17661 or later, and you're not using the single_threaded_observable_vector class that's provided with the topic, then you'll be using winrt::single_threaded_observable_vector, which is a function. If that's the case then that's consistent with the compiler error. I haven't properly updated the topic to show how to use winrt::single_threaded_observable_vector, because it's still in Preview and hasn't yet been released. But there's info about it in this video: https://www.youtube.com/watch?v=nOFNc2uTmGs&feature=youtu.be&t=1h5m46s.

For folks using the released SDK (version 17134), one thing I forgot to add to the topic is that you need to #include "single_threaded_observable_vector.h" in BookstoreViewModel.h.

I'll go ahead and make these fixes to the topic asap. Please let me know if you're still blocked with the info above.

-Steve

schlzber commented 6 years ago

Hello Steve,

thanks for you explanation. I was using the 17713 Preview SDK. I switched back to the 17134 SDK and included the header and now it works. Thanks. :-)

Daniel

stevewhims commented 6 years ago

Great, thanks, Daniel!