In C++, you cannot pass a non-static member function (like Motor::step) directly to a handler expecting a simple function pointer, because member functions require a specific object instance (this) to operate.
Your task is to use a Lambda to "glue" a generic driver to a specific object instance.
Driver:std::function<void()> callback.void execute() calls the callback if valid.void setCallback(std::function<void()> cb).Motor:int position (Initialize to 0).void step(): Increments position and prints Position: <new_pos>.main:Driver and Motor.motor instance by reference and calls its step() method.Program Flow:
Driver and Motor.N.N times.cmd.cmd is "TRIG", call driver.execute().Input Format:
N.N lines: String cmd ("TRIG" or other).Output Format:
Position: <value>Example:
Example 1
Input:
2
TRIG
TRIGOutput:
Position: 1
Position: 2Constraints:
std::function in the Driver.main.motor by reference ([&]) in the lambda.
Input
2 TRIG TRIG
Expected Output
Position: 1 Position: 2