| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
The overloaded constructer ( i think its called that) is like :
Player(string plclass,int mLvl,int mHP,int mMP,int mArmour,int mDmg) { plclass = plclass; mLvl=mLvl; mHP=mHP; mMP=mMP; mArmour=mArmour; mDmg=mDmg; } and the first time i create one is Player MyPlayer("dummy",10,1,2,4,5); and then i mean to change the values of MyPlayer as the program goes on. Whats happening is... there seems to be some kind of syntax problem with ("dummy", . when the program is running - MyPlayer contains plclass="" and then massive negative integers for everything else Im thinking the other values are getting filled with garbage because the string part is causing some error which spills into the other members... any help much appreciated.. |
|
#2
|
||||
|
||||
|
Re: string as parameter 1 of a class.. syntax?
Quote:
Put a breakpoint in the constructor, and check that it's actually called. If so, keep following the content of your variables to see if there are changed. |
|
#3
|
|||
|
|||
|
Re: string as parameter 1 of a class.. syntax?
Use names for the parameters that are different to the names of the class members or use the initializer list.
The parameter names shadow the members. Kurt |
|
#4
|
||||
|
||||
|
Re: string as parameter 1 of a class.. syntax?
Quote:
).You can do this too : Code:
Player::plclass = plclass; |
|
#5
|
|||
|
|||
|
Re: string as parameter 1 of a class.. syntax?
I am wondering if it should llok more like this?
class Player { //Attributes should all have m in front in the class attributes (Not sure if it confuses it in your constructor?// Private: string mplclass; int mLvl; int mHP; etc.... //Methods Public: Player( string plclass, int Lvl, int HP, int MP, int Armour, int Dmg); }; Player::Player(string plclass,int Lvl,int HP,int MP,int Armour,int Dmg) { mplclass = plclass; mLvl=Lvl; mHP=HP; mMP=MP; mArmour=Armour; mDmg=Dmg; } I dont know for sure if this will help. I am new to using classes. But it is worth a shot I say. Good Luck! |
|
#6
|
|||
|
|||
|
Re: string as parameter 1 of a class.. syntax?
Quote:
However all the integers are still massive negatives.... I havent altered the numbers yet, they seem to just do that instead of being 10 or whatever i put there. |
|
#7
|
|||
|
|||
|
Re: string as parameter 1 of a class.. syntax?
Show the code.
Kurt |
|
#8
|
|||
|
|||
|
Re: string as parameter 1 of a class.. syntax?
got it. Was a shadowing issue. Thanks for the tip just had to double check everything twice.
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|