You are awesome! I took out all the parameters for the default constructors for Room and Monster like you said -- works like a charm
you're good
You are awesome! I took out all the parameters for the default constructors for Room and Monster like you said -- works like a charm
you're good
Last edited by GrNxxDaY; 07-31-2002 at 07:04 AM.
AOL: GrNxxDaY
IDE: Dev-C++ Beta 5 (v4.9.4.1)
Project: Eye of Sahjz (text-RPG)
If you think I may need help, please IM me.
The default Room constructor:
Remember these create useless rooms, no names, descriptions, exits, monsters or anything. Same with the default Monster constructor.Code:Room::Room( ) { r = c = 0; //unsure about what this does so I'll just set it to 0 N = E = S = W = false; name = descr = NULL; }
Overloaded = operators are required so that you can do things like this safely:
Just working on a bit of the overloaded = then I'll post thatCode:Monster m1, m2; m1.changeSomething( ); m2 = m1; //= used here
Couldn't think of anything interesting, cool or funny - sorry.
hermm.. try not to change TOO much to the point where it is unreadable by me, a n00b (see the avatar?). If you do change something, do you think you could explain? I just started C++ 3 weeks ago!.
AOL: GrNxxDaY
IDE: Dev-C++ Beta 5 (v4.9.4.1)
Project: Eye of Sahjz (text-RPG)
If you think I may need help, please IM me.
OK but you will need it if you are going to use strings represented as char*'s. Here is part of the overloaded assignment, if its too complex say so and you should probably use string objects instead.
The compiler creates a default operator for your classes but that would just copy rvalue.name into name leaving 2 objects pointing at the same space to represent name. Therefore if you change 1 then the other would also change, not good.Code:Monster& Monster::operator =( Monster& rvalue ) { //routine assignent of values alive = rvalue.alive; maxHP = rvalue.maxHP; curHP = rvalue.curHP; str = rvalue.str; agi = rvalue.agi; gold = rvalue.gold; xp = rvalue.xp; //create space for name attribute name = new char[ strlen( rvalue.name )+1 ]; if( name == NULL ) { cout << "Insufficient memory, exiting...."; exit( 0 ); } else { strcpy( name, rvalue.name ); //copying name } return *this; //UNFINISHED }
By the way, your doing much better than I was after 3 weeks - I wasn't even on to pointers until week 4!
Last edited by endo; 07-31-2002 at 07:28 AM.
Couldn't think of anything interesting, cool or funny - sorry.
EEP - yes, that all looks very complex and the only part I understand is:
I see you have *this pointer.. I can't get that far in my C++ book cause the author expects me to already understand everything.Code:cout << "Insufficient memory, exiting....";
& I'm hesitant to use the new[] thingy because I dont understand the benefits of it or what dynamic memory really is...
Since i'm too n00bish, i should use string types instead of char*?
Last edited by GrNxxDaY; 07-31-2002 at 07:36 AM.
AOL: GrNxxDaY
IDE: Dev-C++ Beta 5 (v4.9.4.1)
Project: Eye of Sahjz (text-RPG)
If you think I may need help, please IM me.
you could do, but you could also use char arrays. Just declare name as char name[ 20 ] or something then treat them as char*'s after that. That way you will know exactly how much space you have every time.
or you could declare them as string objects, which takes care of most of that stuff for you.
string name;
string attack;
etc.
etc.
If you do that the set them to an empty string in the constructor:
name = "";
Hope that helps, the char arrays are more educational but string objects are simpler to use.
Couldn't think of anything interesting, cool or funny - sorry.
thanks for helping with those constructors - you saved me hours of pressing the re-build button.
i have no idea what i'm gonna do about those char*'s now though. I'd like to learn why I need all that overloaded operator stuff - but i'm too stupid to comprehend it =P.
Thanks again for spending the time to help!
AOL: GrNxxDaY
IDE: Dev-C++ Beta 5 (v4.9.4.1)
Project: Eye of Sahjz (text-RPG)
If you think I may need help, please IM me.
No problem I remember how tough it is when you are starting. I'd suggest using string objects for now though, they are nice and versatile
Last edited by endo; 07-31-2002 at 07:52 AM.
Couldn't think of anything interesting, cool or funny - sorry.