Go Down

Topic: Array of pointers to objects (Read 475 times) previous topic - next topic

raymadigan

I have a library, I use to implement a class system for my application, named tcDevice.  It has a complex instantiation method, but it isn't important to my question.

In my application I can have from one to 3 instances of the object and I want to create a global array of pointers to this class that I can fill in at a later time.

I have tried many options around

#define devCount 4
tcDevice *myDevices[devCount];

It seems it want to create the instances.  But I don't know enough to create them at this time.

Any help would be greatly appreciated.

Nick Gammon

That's hard to answer. Can you post a complete sketch that demonstrates this? That snippet doesn't prove much.

Quote
It seems it want to create the instances


Oh? Seems to? Does? Doesn't?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Professor Chaos

Are you saying the constructor is called when you declare the array of pointers?

Nick Gammon

Code: [Select]
tcDevice *myDevices[devCount];

That doesn't create anything. It reserves some memory (for pointers, not instances of the object).

You might want to look up the "new" operator.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

@OP: Please don't delete a thread once it has been answered.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up