OO arduino create instance of a class inside a class

Hi I was just wondering in arduino land how you create an instance if a class inside a class?

I have a class that inherits from stepper and inside it I'd like it to be responsible for creating an instance and holding a reference to an instance of another custom class as well as some inbuilt library classes..

Does anyone have a decent tutorial on doing this? I come from Java land

Like you declare any other variable... Nothing special about classes.

Thomen:
Hi I was just wondering in arduino land how you create an instance if a class inside a class?

I have a class that inherits from stepper and inside it I'd like it to be responsible for creating an instance and holding a reference to an instance of another custom class as well as some inbuilt library classes..

Does anyone have a decent tutorial on doing this? I come from Java land

You want to learn about inheritance, or how to create an object in a class?

If your class member object touches hardware, just be sure to create an initializing member function to call in setup() (or run time instantiation) to do that work(i.e. Serial.begin()).

BulldogLowell:
You want to learn about inheritance, or how to create an object in a class?

If your class member object touches hardware, just be sure to create an initializing member function to call in setup() (or run time instantiation) to do that work(i.e. Serial.begin()).

That is ONLY needed if you're creating a global instance of the class...

Regards,
Ray L.

RayLivingston:
That is ONLY needed if you're creating a global instance of the class...

Regards,
Ray L.

thus the the:

 (or run time instantiation)

BulldogLowell:

 (or run time instantiation)

COMPLETELY unnecessary for run-time instantiation. The class constructor is all that's needed.

Regards,
Ray L.

RayLivingston:
COMPLETELY unnecessary for run-time instantiation. The class constructor is all that's needed.

Regards,
Ray L.

Not necessarily... what if your class Constructor hasn't initialized the hardware?

Setting pinMode() would be a nice little example.

Look at the Servo library...

Not trying to be argumentative but I'm right(er). :wink: