Template type is not “seen” by the compiler inside a 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 to "see" Wcf without problems, I even use it: wcf->itemCount.

Is there any workaround or reason why this is happening?

Answers


Don't know why it doesn't work. 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);
    });
}

Need Your Help

Raising events from a mock/stub using Rhino Mocks

c# unit-testing events rhino-mocks

How can I raise an event from a mock/stub using Rhino Mocks?

Unable to start UE4Editor.exe

c++ visual-studio visual-studio-2013 remote-debugging unreal-engine4

Trying to launch the editor from Visual Studio 2013 Ultimate I get the following error in the title. VS says it's because it can't reach MSVSMON.EXE on a "remote computer", the weird thing is that ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.