Pages: [1]   Go Down
Author Topic: Array of pointers to objects  (Read 441 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19040
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged


0
Offline Offline
Full Member
***
Karma: 1
Posts: 225
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19040
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19040
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Pages: [1]   Go Up
Jump to: