1

Never used lambdas before and I can't understand where I'd have to add it.

My Error is "Show: Ambigious call to overloaded function"

Show() can take 2 types CustomizeToast and CustomizeToastAsync. So I guess I need to specify CustomizeToast somewhere but I can't for the life of me see where.

This is my current code:

ToastContentBuilder()
    .AddText(L"Hello World!")
    .Show([](ToastNotification const& toast) -> void
    {
       toast.Tag(L"1");
    });

Error:

error C2668: 'winrt::impl::consume_Microsoft_Toolkit_Uwp_Notifications_IToastContentBuilderClass<winrt::Microsoft::Toolkit::Uwp::Notifications::IToastContentBuilderClass>::Show': ambiguous call to overloaded function
Microsoft.Toolkit.Uwp.Notifications.0.h(2159,60): message : could be 'auto winrt::impl::consume_Microsoft_Toolkit_Uwp_Notifications_IToastContentBuilderClass<winrt::Microsoft::Toolkit::Uwp::Notifications::IToastContentBuilderClass>::Show(const winrt::Microsoft::Toolkit::Uwp::Notifications::CustomizeToastAsync &) const'
Microsoft.Toolkit.Uwp.Notifications.0.h(2158,31): message : or       'auto winrt::impl::consume_Microsoft_Toolkit_Uwp_Notifications_IToastContentBuilderClass<winrt::Microsoft::Toolkit::Uwp::Notifications::IToastContentBuilderClass>::Show(const winrt::Microsoft::Toolkit::Uwp::Notifications::CustomizeToast &) const'
message : while trying to match the argument list '(winrt::MyApplication::implementation::Toast::ShowToastNotification::<lambda_786678859ea03b85c00686eebdcb39db>)'

Project is an UWP project using the Microsoft.Toolkit.Uwp.Notifications

3
  • 2
    Please provide full error message, in addition to minimal reproducible example. Commented May 19, 2021 at 12:19
  • if Show can either take a CustomizeToast or a CustomizeToastAsync and both can be constructed from the lambda, then the compiler cannot know which one to pick. I have to guess, but the complete compiler error should tell all this in a much more concise way. Without code and complete error message we can only guess Commented May 19, 2021 at 12:32
  • Added Error Message, this is all I have in my ShowToastNotification function and should work fine with an empty UWP Solution and the Microsoft.Toolkit.Uwp.Notification Package Commented May 19, 2021 at 12:42

1 Answer 1

1

Show() can take 2 types CustomizeToast and CustomizeToastAsync.

This is clearly an oversight on the API's developpers end. Now since both classes can be constructed from a lambda the compiler doesn't know which one to use, so you have to guide it:

ToastContentBuilder()
    .AddText(L"Hello World!")
    .Show(CustomizeToast{[](ToastNotification const& toast) -> void
    {
       toast.Tag(L"1");
    }});

This is less readable and cumbersome, but constructing syntaxic suggar for it would be error-prone and a bit convoluted.

Sign up to request clarification or add additional context in comments.

9 Comments

"This is clearly an oversight on the API's developpers end." - Or, just something one has to live with when C++' overly complex overload resolution kicks in. If you cannot help it but need to point fingers, don't ignore what a mess C++ has turned into.
@IInspectable I stand by my words.
Don't think you can really blame C++ here. It would be trivial for the API developers to add an ShowCustomizeToast method, not overloaded. This will not break any existing code, and be a pure extension. The overloaded Show(CustomizeToast) would then be a simple shorthand, and probably an inline wrapper.
The API developer doesn't know about C++, nor lambda expressions. Nor about crazy constructors that take function-like objects.
@IInspectable I'm lost. Is it not a C++ API? Shouldn't its devs know of a major, 10-years-old C++ feature?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.