![]() |
| ||
| How to adjust class objects through seperate class functions??? I want to create a battle system for an RPG game, one a little more robust then the previous one I made. This one I want to be very dynamic and easy to use. I want to use the Allegro API for it, but first I want to make sure I have everything going good in console before I put it into a real time rpg, but I'm having technical difficulties... Now here are my classes...
Right now I want to pass the Boxer class' HP through a pointer to the Battle Classes Attack function, while passing a normal int (since the attack really doesnt need to be adjusted as of now). I get really weird errors like no matching function for call to `Battle::Battle(int&, int)'|... Please help!!! |
| ||
| Re: How to adjust class objects through seperate class functions??? Well I can see a few issues with this code. First of all, when someone gets hit, i assume they would lose hp, not gain it. And as to the actual problem, the Boxer class doesn't contain a member called hp. The best way to do something like this is to make all the members in your classes private, then make some public accessor methods like this: class Boxer:Game{Voila. No pointers required. And much more dynamic as well. |
| ||
| Re: How to adjust class objects through seperate class functions??? This might not seem dynamic, since a boxer is required as an argument rather than an arbitrary pointer, but I'm making the assumption that if you would like to include more types of boxers/etc that you would derive these classes from the basic boxer class, in which case you could make GetHP() and SetHP() polymorhpic (ie virtual methods). But you don't seem to be at this stage yet, so this should suffice. |
| ||
| Re: How to adjust class objects through seperate class functions??? so far ty, however i have 2 questions, I dont know why I need a const in there, and I cant find any really helpful tuts on polymorphism and class deriving, can you lead me to a good one :P |
| ||
| Re: How to adjust class objects through seperate class functions??? Quote:
2. I can't think of any good tutorials off the top of my head. Your best bet would be to take an intermediate c++ course. Or google polymorphism and base class inheritance. |
| ||
| Re: How to adjust class objects through seperate class functions??? ugh can you just show me what you would do in the int main() too I'm really having severe problems, me and pointers are just not friends |
| ||
| Re: How to adjust class objects through seperate class functions??? int main(){This would work. But your code is fundamentally sloppy. Are you trying to teach c++ to yourself? I wouldn't recommend that, since c++ is the most complicated programming language in the world, in my opinion (next to Lisp). Try C# or VisualBasic. Or take a course on c++. Or if you're really addemant about teaching yourself, prepare for a long and frustrating battle. |
| ||
| Re: How to adjust class objects through seperate class functions??? Yes, I've been teaching myself for awhile. I'm fine with most aspects, its just pointers have always kicked my ass in one way or another, like the compiler will expect me to put something in that pointing to the pointer of something (**) and I'll google, not figure it out, then just post here. This is due to the fact that you guys rawk!!! thx much skata :) |
| All times are GMT -4. The time now is 4:01 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC