c++ - How to pass lambda to overridden method with boost::function parameter? -


i've got class constructors defined this:

lambdajsonvisitor(); lambdajsonvisitor(boost::function<void (const value &)> f); lambdajsonvisitor(boost::function<void (const object &)> f); lambdajsonvisitor(boost::function<void (const keyvaluepair &)> f); lambdajsonvisitor(boost::function<void (const array &)> f); 

and i'm trying construct object this:

lambdajsonvisitor setnodeidvisitor([&](const jsonapi::value &val) -> void {     ... }); 

when try compile it, i'm getting following compiler error:

4>netmodel\cnetworkalarmbuilder.cpp(60): error c2668: 'jsonapi::lambdajsonvisitor::lambdajsonvisitor' : ambiguous call overloaded function 4>          c:\workspace\client\projects\jsonparser\api/lambdajsonvisitor.h(21): 'jsonapi::lambdajsonvisitor::lambdajsonvisitor(boost::function<signature>)' 4>          4>          [ 4>              signature=void (const jsonapi::array &) 4>          ] 4>          c:\workspace\client\projects\jsonparser\api/lambdajsonvisitor.h(20): or       'jsonapi::lambdajsonvisitor::lambdajsonvisitor(boost::function<signature>)' 4>          4>          [ 4>              signature=void (const jsonapi::keyvaluepair &) 4>          ] 4>          c:\workspace\client\projects\jsonparser\api/lambdajsonvisitor.h(19): or       'jsonapi::lambdajsonvisitor::lambdajsonvisitor(boost::function<signature>)' 4>          4>          [ 4>              signature=void (const jsonapi::object &) 4>          ] 4>          c:\workspace\client\projects\jsonparser\api/lambdajsonvisitor.h(18): or       'jsonapi::lambdajsonvisitor::lambdajsonvisitor(boost::function<signature>)' 4>          4>          [ 4>              signature=void (const jsonapi::value &) 4>          ] 4>          while trying match argument list '(`anonymous-namespace'::<lambda1>)' 

is possible pass lambda parameter overridden constructor this? if so, doing wrong , how should change code make work? i'm using visual studio 2010.

thanks

it can't work when there derived types example can fixed creating object , casting right type, like

auto lambda = [&](const c&) {}; func f(static_cast<std::function<void(const c&)>>(lambda)); 

or without creating object like

func f(static_cast<std::function<void(const c&)>>( [&](const c&) {}); 

example


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -