Jump to content
  • Advertisement
Sign in to follow this  
Rowen

=== Database Problemes ===

This topic is 4765 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone!!! I am making a database using classes, but I have 2 problemes: 1. I need to be able to save AND load informations typed in by the user. 2. If the user types for example "Data01" for a name for new data (type: char), then I need to be able to create an instance of my class using that name. Thanks in advance!!!

Share this post


Link to post
Share on other sites
Advertisement
You may need to ask a question of some sort, if you want an answer... And perhaps give some additional information about things such as language, api and what database you are trying to use (if that is what you are doing).

Share this post


Link to post
Share on other sites
nice flaming =)
look in google about object factories. thats the pattern which will help u.
Maybe ur class should contain an union-struct, so the factory can decide, which datatype it needs.

Share this post


Link to post
Share on other sites
Hmmm... Not good at this posing questions-business am I?

Well sorry, but here is (hopefully) what you need:

- I am using C++

- The Dev-C++ Environment

- I am making a database to store information about monsters for a roleplaying game called Dungeons & Dragons. This means it will imply data of type char because it is not numbers but text that the program will prompt the user for.

Oh, and I am making (at least trying too) the database myself but if you have any other suggestions of what is better feel free to do so.

Thanks in advance!!!

Share this post


Link to post
Share on other sites
I say you make a struct/class to hold you monster:


class CMonster
{
public:
CMonster(const string &rsName, int iLevel, ...);
string GetName() const;
...

private:
string m_sName;
int m_iLevel;
...
};





then create a list of these monsters:



list<CMonster *> lstMonsters;

lstMonsters.push_back(new CMonster("Mr. Smily", 1024));
lstMonsters.push_back(new CMonster("Iron-Fist", 0));

...




(just be sure to free all the monsters ;-) when you delete the list)

then when you need to find a monster:


CMonster *GetMonster(const string &rsName, list<CMonster *> &rlstMonsters)
{
for (list<CMonster *>::iterator iter = rlstMonsters.begin(); iter != rlstMonsters.end(); iter++)
{
if ((*iter)->GetName() == rsName)
return (*iter);
}

return NULL;
}





ok, so there's a lot of problems with my code, but it should point you in the right direction.

-ßrice

Share this post


Link to post
Share on other sites
Thanksm, I will try to do what i can, though I still think I need to start with something less complicated :)

Share this post


Link to post
Share on other sites
I'm flatted that you think my solution complicated, but it's actually simple C++ (and STL). If you have any problems understanding the code, you can check out CProgramming.com -- wonderful tutorials about the C/C++ language and things related to it.

-ßrice

P.S. Check under the section titled "C++ Standard Template Library (STL)" for more about lists.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!