Do you mean add new members to an array that's already been declared? That's not possible. You'll either have to use vectors or a linked list. Linked lists look like this:
class LinkedList {
public:
int mydata;
// etc..
LinkedList *next;
};
Where next points to the next node in the structure.
Vectors are similar in the fact that they too can dynamically add data, but they're really classes that are templates. For example:
std::vector<classtype> classvector_instance;
And then you can add or remove nodes by using the vector's member functions push and pop , respectively.
Then all you'll need to worry about is the class constructor, and not bother with an insert member function.
More information on linked lists and vectors: http://www.fortunecity.com/skyscraper/false/780/linklist.html
http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4027/
Hope this helps
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
No, the syntax of vectors is different, and you don't need to declare how many nodes are going to be in it (although you can, but in this case it's kind of pointless), you just add them as you ned them:
class company {
// ...
protected:
std::vector<managers> themanagers;
std::vector<casuals> thecasuals;
std::vector<salesstaff> thesalesstaff;
};
// eg.
themanagers.push_back(/*initalization data for constructor*/);
And then you can access any node in a vector exactly the same as you would a regular array.
themanagers[index_var].member_data = whatever;
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Sorry about the late(ish) reply! I had this post written, and then my computer messed up, so I wasn't able to post it.
string object_name
Missing semicolon.
if (temptype == 'casual')
Use double quotes for a string, not singles.
Vector syntax looks good, though!
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
if (temptype == 'casual')
{ // I think you missed this brace here.
casual object_name; // Removed the brackets.
// causal object_name() is a function called object_name that returns a causal object.
// You want a instance of class causal.
thecasuals.add_casual(object_name);
}
//.. rest of the else ifs
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
And you should read mr. joe's post again:
if (temptype == 'casual') => if (temptype == "casual")
string object_name => string object_name;
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403