Here's what I want to achieve: I'm building a class for controlling step motors. In that class I want to have a method called "init". In that method I'd like to create an object of class Tone, which I'll need to control a motor. BUT I want to have seperate Tone class object for every object of my class that I create. How can I do it?
So, for exmaple, if I have:
myClass newmotor1;
memotor1.init();
After executing these two lines, I'd like to have my object newmotor1 (which I have, because I just created it) AND an object of class Tone, which I'll use.
1 Answer 1
You don't need to "create" anything. Just have an object in your class:
class Tone {
public:
void dosomething() {
// Whatever is in here
}
};
class MyMotor {
public:
Tone tone;
void init() {
// Nothing much else to do in here now.
}
};
You then:
MyMotor newmotor1;
And you can access:
newmotor1.tone.dosomething();
init
function? Why not just have one in the class already?