The type of the template is not "visible" by the compiler inside the lambda
template<typename Wcf, typename Wdb>
void ComputeGenericDropCount(const function<void(Wdb *, int)> &func)
{
Wcf::ForEach([&](Wcf *wcf) {
Wdb *wdb = Wdb::Find(wcf->sourceId); // <--- ERROR
// error C2653: 'Wdb' : is not a class or namespace name
if(wdb)
func(wdb, wcf->itemCount);
});
}
It's weird, because it seems that "see" Wcfno problem, I even use it: wcf->itemCount.
Is there any workaround or reason why this is happening?
I don’t know why this is not working. But here is a workaround.
template<typename Wcf, typename Wdb>
void ComputeGenericDropCount(const function<void(Wdb *, int)> &func)
{
auto my_find = Wdb::Find; // allows lambda to "capture" the correct function.
Wcf::ForEach([&](Wcf *wcf)
{
Wdb *wdb = my_find(wcf->sourceId);
if(wdb)
func(wdb, wcf->itemCount);
});
}