Hey everyone,
I have the following code (Modified to reduce size) :
Code:
//! statically create commands
static cmd_debug _debugcmd;
static cmd_title _titlecmd;
static cmd_timeout _timeoutcmd;
//! add commands
internal_cmds[0] = (internal_cmd*)&_debugcmd;
internal_cmds[1] = (internal_cmd*)&_titlecmd;
internal_cmds[2] = (internal_cmd*)&_timeoutcmd;
All of the cmd_* classes derive from a pure virtual base class, internal_cmd. By storing all commands into an array of abstract pointers, I can work with any command using the same base class interface.
The problem that I dont like is the repetitiveness of this code. I have to statically create an object for each command and manually add them to the array, one at a time. Yuck.
Im looking for a better method that will let me dynamically add commands to the array...
without using dynamic memory allocation of any kind nor STL as neither are implemented in this code running environment. I cant think of a way without needing dynamic memory though...
I *can* use a pointer to some location in memory to mimic dynamic memory though, but I am looking for a cleaner method as doing this may be dangerous as I would not know what is there in memory.
Does anyone have any better alternative methods that I can try?
Thanks!
*btw, What happened to the delete thread post button?