CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Deploying Windows Server 2008 with System Center
  • Remote Desktop Protocol Performance Improvements in Windows Server 2008 R2 and Windows 7
  • The Microsoft Dynamics CRM Security Model
  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 8th, 2009, 01:19 PM
    lemadness lemadness is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 10
    lemadness is an unknown quantity at this point (<10)
    Lightbulb string as parameter 1 of a class.. syntax?

    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..
    Reply With Quote
      #2    
    Old November 8th, 2009, 01:22 PM
    Skizmo's Avatar
    Skizmo Skizmo is online now
    Elite Member
     
    Join Date: Sep 2004
    Location: Holland (land of the dope)
    Posts: 2,822
    Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+)
    Re: string as parameter 1 of a class.. syntax?

    Quote:
    Im thinking the other values are getting filled with garbage because the string part is causing some error which spills into the other members
    Highly unlikely.

    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.
    Reply With Quote
      #3    
    Old November 8th, 2009, 01:24 PM
    ZuK ZuK is offline
    Senior Member
     
    Join Date: Oct 2002
    Location: Austria
    Posts: 1,094
    ZuK is a glorious beacon of light (400+) ZuK is a glorious beacon of light (400+) ZuK is a glorious beacon of light (400+) ZuK is a glorious beacon of light (400+) ZuK is a glorious beacon of light (400+) ZuK is a glorious beacon of light (400+)
    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
    Reply With Quote
      #4    
    Old November 8th, 2009, 01:27 PM
    Skizmo's Avatar
    Skizmo Skizmo is online now
    Elite Member
     
    Join Date: Sep 2004
    Location: Holland (land of the dope)
    Posts: 2,822
    Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+) Skizmo is a name known to all (1000+)
    Re: string as parameter 1 of a class.. syntax?

    Quote:
    Originally Posted by ZuK View Post
    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
    Doh... that's the problem (that I didn't see that ).

    You can do this too :
    Code:
    Player::plclass = plclass;
    Reply With Quote
      #5    
    Old November 8th, 2009, 01:29 PM
    Shadow_Govt Shadow_Govt is offline
    Member
     
    Join Date: Jan 2009
    Posts: 72
    Shadow_Govt is an unknown quantity at this point (<10)
    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!
    Reply With Quote
      #6    
    Old November 8th, 2009, 01:32 PM
    lemadness lemadness is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 10
    lemadness is an unknown quantity at this point (<10)
    Re: string as parameter 1 of a class.. syntax?

    Quote:
    Originally Posted by ZuK View Post
    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
    Now that i have done this - My player function will take on the string parameter. half sorted thanks mate

    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.
    Reply With Quote
      #7    
    Old November 8th, 2009, 01:34 PM
    ZuK ZuK is offline
    Senior Member
     
    Join Date: Oct 2002
    Location: Austria
    Posts: 1,094
    ZuK is a glorious beacon of light (400+) ZuK is a glorious beacon of light (400+) ZuK is a glorious beacon of light (400+) ZuK is a glorious beacon of light (400+) ZuK is a glorious beacon of light (400+) ZuK is a glorious beacon of light (400+)
    Re: string as parameter 1 of a class.. syntax?

    Show the code.
    Kurt
    Reply With Quote
      #8    
    Old November 8th, 2009, 01:56 PM
    lemadness lemadness is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 10
    lemadness is an unknown quantity at this point (<10)
    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.
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 03:02 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.