Go Down

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


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.

It seems it want to create the instances

Oh? Seems to? Does? Doesn't?

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.

Nick Gammon

@OP: Please don't delete a thread once it has been answered.

Go Up