Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
I'm writing a Multiplayer-Role-Playing-Game. Don't worry, I don't plan to have everyone on at the same time, but more of an organizer, and records keeper. I'm writing it in C++ to give myself a little challenge, and learn. One of the awesome benifits of BM is the undefined arrays with an unlimited number of elements openly changeable. I'd like to in my game allow my Users (players playing the game) to have an unlimited amount of Characters, but as far as my knowledge you can't even have an array of Classes, let alone an undefined array (not sure if possible in C++) of Classes. Is there a way to make this possible? ------------------ I reserve the full right to change my views/theories at any time. |
|
Jari![]() Member Posts: 1471 From: Helsinki, Finland Registered: 03-11-2005 |
Hmm strange, I posted a reply to this thread earlier... Test 123... ------------------ [VoHW] (Help needed) [Blog] - Truedisciple (mp3) |
|
Jari![]() Member Posts: 1471 From: Helsinki, Finland Registered: 03-11-2005 |
okay seems to work... now to you answer your question mene-mene, it should be possible using some container class like STL's list. Like this:
Where Character is the c++ class. ------------------ [VoHW] (Help needed) [Blog] - Truedisciple (mp3) |
|
Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
Thanks for the help, not entirely sure what you mean by your example. What about undefinesd size arrays? I'm considering just making the limit 24/23. Edit: nvm. I'll just make the limit of player characters to 24, shouldn't have more than that anyway. Edit 2: I'm recieving a weird error saying that, "44 D:\My Documents\Computer Programing\C++\SW PNR II.cpp no matching function for call to `std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(std::string&)' ". Here's a cut-up part of the code,
The last line is the one thats generating the error. ------------------ I reserve the full right to change my views/theories at any time. [This message has been edited by Mene-Mene (edited February 25, 2007).] [This message has been edited by Mene-Mene (edited February 25, 2007).] |
|
Jari![]() Member Posts: 1471 From: Helsinki, Finland Registered: 03-11-2005 |
Yeah ostream is bit silly because it doesnt take string but const char* So you have to do: ofstream UserFolder ( UserName.c_str() ); to get the "const char*" (pointer to the string) ------------------ [VoHW] (Help needed) [Blog] - Truedisciple (mp3) |
|
spade89![]() Member Posts: 561 From: houston,tx Registered: 11-28-2006 |
how about a vector?? ------------------ |
|
luke![]() Member Posts: 311 From: I use your computer as my second Linux box Registered: 10-30-2005 |
This may be beating a dead horse now, but dead horses are easy beatn heres a top off on ArrayList (Java class, but the concept will do) LinkedList (Ever heard of it? std::list) Alrighty, arraylist is essentially an array which 'dynamically resizes' itself when it needs more space. What this means is that when it runs out of space, it makes a new array of size = oldSize + minAdditionalLength; and then copies over the data. If you are dealing with large amounts of data, you want to avoid those copy operations. Linked list: Is essentially defined as: Think about that and you will come to two conclusions. For your specific case, only an addict should have more than 10 characters or some other reasonable number, so I would say LinkedList is your bet. The C++ equivalent of LinkedList is std::list, as suggested above. ------------------ [This message has been edited by luke (edited February 26, 2007).] |