私はこれで初めてです。どのようなクラス構造が必要ですか?
私はモーターオブジェクトと定義済みのコールバック関数(割り込みでトリガーされる)を含むロボットクラスを持っています。私はachiveしようとしています何
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
}
は次のとおりです。
- ロボットとモーターオブジェクトは一度作成する必要があります(実際の物理ロボットとモーターに接続されているため、1つのロボットと1つのモーターのみが許容されます)
- モーターオブジェクト(
motor1
)は、重要なことは、あらかじめ作成されたcallback
関数から呼び出すことができるはずです。
だから、メインは、私は本当にことをお勧めしたいが、明らかにSingleton Patternが頭に浮かぶことはない
main(){
robot myRobot;
robot myRobot2; //is not allowed or should be useless
printf("%d\n", myRobot.motor1.getPosition());
}
コールバック関数のユーザーパラメータをインストールできますか? – user0042
[This](https://stackoverflow.com/questions/1008019/c-singleton-design-pattern)が役立ちます。 –
"GetOrCreate"関数のようなものを書くことができますか? 'ロボット'は何かによって管理されるべきですか? – George