typedef std::function<void()>VoidFunctionPtr; InvokeFunction invokePtr;…
- User
typedef std::function<void()>VoidFunctionPtr; InvokeFunction invokePtr; holder->RegisterMethod("EnterSVelPointEdit", &invokePtr {invokePtr.EnterSVelPointEdit(); });
codeEvent* event3 = new Event("ClickStartPoint", "InvokeMethod", "EnterSVelPointEdit");what is the use of std::function<void()>VoidFunctionPtr here? what are the limitation if we use typedef void(*FunctionPointer)(); ?
- Assistant
- User
typedef std::function<ToolState(int, ToolsType)>ToolstatefunctionPtr; void MethodHolder::RegisterMethod(const std::string& methodName, ToolstatefunctionPtr methodPtr) { ToolstateMethodMap[methodName] = methodPtr; } FixedPolygonTool polygonPtr; holder->RegisterMethod("getToolState", [&](int frameNumber, ToolsType toolType) {return polygonPtr.getToolState(frameNumber, toolType); });
- Assistant
- User
Maintaining State: Using a lambda allows capturing values or references from the surrounding context, which would not be possible with simple function pointers. explain this statement with the above example
- Assistant
- User
void MethodHolder::RegisterMethod(const std::string& methodName, ToolstatefunctionPtr methodPtr) { ToolstateMethodMap[methodName] = methodPtr; }
ToolState MethodHolder::InvokeToolState(const std::string& methodName,ToolsType toolType) { auto it = ToolstateMethodMap.find(methodName); if (it != ToolstateMethodMap.end()) { return it->second(toolType); } else { std::cout << "Method not found: " << methodName << std::endl; } } FixedPolygonTool polygonPtr; holder->RegisterMethod("getToolState", [&](ToolsType toolType) {return polygonPtr.getToolState(toolType); }); ToolState state = holder->InvokeToolState("getToolState",ToolsType::Polygon);
i am getting the below error Severity Code Description Project File Line Suppression State Details Error C2665 'MethodHolder::RegisterMethod': no overloaded function could convert all the argument types FsmImplementation C:\Users\1038586\Downloads\FsmImplementation11142024\FsmImplementation\FsmImplementation\FSMBase.cpp 79 Error C2064 term does not evaluate to a function taking 1 arguments FsmImplementation C:\Users\1038586\Downloads\FsmImplementation11142024\FsmImplementation\FsmImplementation\MethodHolder.cpp 21
- Assistant