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
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.
Related
This is my first time using threads in c++ and I have some issues with it. I am getting error
error: no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>, __gnu_cxx::__alloc_traits<std::allocator<packetInfo> >::value_type*)’
This is my code excerpt:
std::vector<packetInfo> sentPackets; // global var
void renewIP(struct packetInfo *currentPacket) {
...//code
}
void anotherFuntion() {
...
std::thread renewTimer(renewIP, &(sentPackets[i]));
renewTimer.detach();
...
}
I have absolutely no idea what am I doing wrong or why am I getting the error.
Thanks.
The error tells you directly:
<unresolved overloaded function type>
You must have multiple overloads of renewIP, and the compiler doesn't know which one you want. You can either rename them to make them not ambiguous, or make it explicit via a cast:
std::thread renewTimer((void(*)(struct packetInfo*))renewIP, &(sentPackets[i]));
In the question How to register member function to lua without lua bind in c++ one answer suggested the following code:
class C {
public:
void blah(lua_State* L);
};
C inst;
lua_pushcclosure(L, std::bind(&C::blah, &inst, std::placeholder::_1), 0);
lua_setglobal(L, "blah");
(Quoted as it stood, including the small error in std::placeholders)
However, I cuold not get that to work. The error message I got back states that the function returned by std::bind can't be converted to a lua_CFunction.
I have also tried changing the return type of blah to int, but I get the same error message. If it's helpful to anyone, the full error message is:
Error C2664 'void lua_pushcclosure(lua_State *,lua_CFunction,int)': cannot convert argument 2 from 'std::_Binder<std::_Unforced,int (__thiscall C::* )(lua_State *),C *,const std::_Ph<1> &>' to 'lua_CFunction'
I even tried to change &C::blah to &inst.blah, but that unsurprisingly didn't work either.
Has anyone gotten it to work? Or is it just not meant to work?
I have these two functions
bool checkIfPlayerWon(const F &field){
return checkIfPlayerWon(field, player);
}
bool checkIfPlayerWon(const F &field, int current_player){
player is a member var of my class.
Now in my main I call
if(human_player.help.checkIfPlayerWon(my_field))
and
if(pc_player.help.checkIfPlayerWon(my_field))
Now everything compiles fine and the program works as intended. But eclipse gives me warnings, that the function checkIfPlayerWon is ambigous and then shows me:
'checkIfPlayerWon' is ambiguous '
Candidates are:
bool checkIfPlayerWon(const playfield &)
bool checkIfPlayerWon(const playfield &, int)
'
Why does eclipse do this? It's clear that it should call the first function, because it only has one argument. The gcc compiler gets it but why not eclipse?
I don't know how to make Eclipse figure out which overloaded function you want, but the ambiguous warning is decently easy to turn off without disabling the entire C++ parser.
Go to Window->Preferences->C/C++->Cody Analysis and write ambiguous in the search tab. Then it will let you toggle the warning off.
I am trying to implement _set_se_translator. I tried to write a function with the following signature (from my .cpp file - of course, I have a similar signature in my .h file):
void CIntersonBScan::trans_func(unsigned int u, EXCEPTION_POINTERS* pExp)
I then pass this function as a parameter to _set_se_translator by writing the following code:
_set_se_translator(&CIntersonBScan::trans_func);
I then compile my code and get the following error message:
error C2664: '_set_se_translator': cannot convert parameter 1 from 'void(__thiscall CIntersonBScan::*)(unsigned int,EXCEPTION_POINTERS *)' to '_se_translator_function'
In the eh.h file, I found the following definition for _se_translator_function:
typedef void (__cdecl *_se_translator_function)(unsigned int, struct _EXCEPTION_POINTERS*);
I tried varying the signature of trans_func and still got the same error message. I already set the /EHa compile option. How to I create a function that would actually match the signature of _se_translator_function?
typedef void (__cdecl *_se_translator_function)(unsigned int, struct _EXCEPTION_POINTERS*);
This must be a free function, or a static member function - it cannot be a non-static member function (because these have a hidden implicit this parameter - and cannot match _se_translator_function).
It needs to be a free standing function, not a member function. That is why the types don't match.
class messageA {
};
class messageB {
};
template<class T>
class queue {
public:
virtual ~queue() {}
void submit(T& x) {}
};
class A : public queue<messageA>, public queue<messageB>
{
};
int main()
{
A aa;
aa.submit(messageA());
aa.submit(messageB());
}
My first thought is, the above code should be fine, as class A will contains 2 overloaded submit functions, which will accept messageA and messageB object.
However, the compiler gives me the following error :
May I know why there is an ambiguous? Isn't it is quite obvious that, for the 1st submit call, I want to call messageA version? For the 2nd submit call, I want to call messageB version?
------ Build started: Project: main, Configuration: Release Win32 ------
Compiling...
main.cpp
.\main.cpp(21) : error C2385: ambiguous access of 'submit'
could be the 'submit' in base 'queue<messageA>'
or could be the 'submit' in base 'queue<messageB>'
.\main.cpp(21) : error C3861: 'submit': identifier not found
.\main.cpp(22) : error C2385: ambiguous access of 'submit'
could be the 'submit' in base 'queue<messageA>'
or could be the 'submit' in base 'queue<messageB>'
.\main.cpp(22) : error C2664: 'queue<T>::submit' : cannot convert parameter 1 from 'messageB' to 'messageA &'
with
[
T=messageA
]
.\main.cpp(22) : error C3861: 'submit': identifier not found
I have no compiler right now, but I guess one inheritance could hide the other : The compiler will use Koenig Lookup to find the right symbol, and if I remember correctly, once the compiler find a suitable symbol (i.e., a method called "submit"), it will stop searching for others in parent and/or outer scopes.
In this case, I thought both inheriting classes would be searched for the symbol, but without your exact compiler (Visual C++ 2003 ? 2008 ? 2010 ?), I cannot guess much more.
After some thoughts, another possibility is that the compiler did find both symbols, but is unable to decide which to call (at that moment of symbol resolution, the compiler cares only for symbol name, not its exact prototype). I believe this last explanation to be the right one.
Try adding using statements in your derived classes :
class A : public queue<messageA>, public queue<messageB>
{
using queue<messageA>::submit ;
using queue<messageB>::submit ;
} ;
to bring both the submit methods directly in the A class scope.
Note, too, that your submit methods are taking messages as non-const reference, while in the constructor, your message parameters are temporaries (and thus, const r-values).
Re-writting the main as:
int main()
{
A aa;
messageA mA ;
messageA mB ;
aa.submit(mA);
aa.submit(mB);
}
could help compile (this could explain the compiler error on line 22).
Or you could change the prototype of your submit methods to accept const references instead of non-const references.
Note: Still without compiler, so trying to brain-debug your code... :-P ...
Something* smth1 = ((Base<Something> *)d)->createBase<Something>();
The above code works fine.