I just needed something like this:
I have got a robot class which contains a motor object and a predefined callback function (which is triggered on an interrupt).
robot.h
class robot
{
public:
motor motor1;
};
motor.h
class motor
{
public:
int incrementPosition();
int getPosition();
private:
int position;
};
callback.cpp
void callback(){
motor1.incrementPosition(); //callback function needs to reach this already created motor1
}
What I am trying to achive is:
- Robot and motor objects has to be created only once (only one robot and one motor are allowable, bacause it is connected to a real physical robot and a motor),
- Motor object (
motor1
) has to be created automatically and most importantly, it should be callable from the prefinedcallback
function.
So the main should be like this,
main(){
robot myRobot;
robot myRobot2; //is not allowed or should be useless
printf("%d\n", myRobot.motor1.getPosition());
}