Thread: help compling with Dev-C++

  1. #1
    Registered User GrNxxDaY's Avatar
    Join Date
    Jul 2002
    Posts
    140

    help compling with Dev-C++

    i try to compile my program and i get this error

    114 sourcecode.cpp
    request for member `setPlayerInfo' in `human', which is of non-aggregate type `Player ()()'

    what's going on??

    human is an instance of a class i made
    setPLayerInfo is a regular public member function

  2. #2
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282

    elaborate

    post some code..

  3. #3
    Registered User GrNxxDaY's Avatar
    Join Date
    Jul 2002
    Posts
    140
    okay

    class declaration, constructor, and member function are here, as well as the call to the funciton

    Code:
    // Player class declaration
    class Player
    {
     private:
             char      playerName;
             short int hitpoints;
             short int strength;
             short int agility;
             short int magic;
             short int gold;
     public:
             Player();                  // constructor
                                        // no destructor
             void reportStats();        // shows stats
             void attack();             // kill monster
             void move();               // move N, E, S, or W (do i need parameters?)
             void rest();               // sleep to regain health
             void setPlayerInfo();      // name, sex
             void showPlayerInfo();         // for debugging only
    };
    
    
    Player::Player()    // constructor definition
    {
     playerName = new char[20];
     strcpy(playerName, "Brian");
     strength = 10;
     agility = 10;
     hitpoints = 10;
     magic = 20;
     gold = 20;
    }
    
    
    void Player::setPlayerInfo()
    {
        clrscr();
        displayTitle();
    
    	std::cout << "What is your name, young traveler?: ";
    	std::cin >> playerName;
    }
    here is the call to the function, which is in main()
    Code:
     human.setPlayerInfo();  // gets playerName and sex

  4. #4
    Registered User GrNxxDaY's Avatar
    Join Date
    Jul 2002
    Posts
    140
    here is the entire project, if that helps (i am using dev-c++)

  5. #5
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    wow ur making an rpg in dev c++ i am two, but my stuff looks a little mor eprimitive and newbieish but oh well. there IS some easier ways to do those using variables and functions tho.
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    16
    I see the problem, you declared "human" with the following line:

    Code:
    Player human();
    Leave out the () part; those are only there if you are not using a default constructor and instead are using one which takes parameters.

    P.S.: I must say, that's an interesting idea for a story.

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    He's right.

    Here are a couple of tips:

    Add two variables to the class, x and y, which will hold the current position of the player, then:



    Code:
    void Player::moveVert(int units)
    {
     char *direction = (units < 0) ? "South" : "North";
     y += units;
     std::cout << playerName << " Has Moved" << units << " Steps To The " << direction << endl;
    }
    
    
    
    void Player::moveHoriz()
    {
     char *direction = (units < 0) ? "West" : "East";
     x += units;
     std::cout << playerName << " Has Moved" << units << " Steps To The " << direction << endl;
    }

    Find out how to capture the arrow keys with _getch(); This way you can use them to control the player.


    Also, in a constructor you can initialize variables en masse like this:

    Code:
    
    Player::Player(char *name = "New Player") //...default name...
    :x(0), y(0), strength(10), agility(10), hitpoints(10), magic(20), gold(20)
     {
      playerName = new char[50];
      strcpy(playerName, name);
     }

    Good luck on your game!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  8. #8
    Registered User GrNxxDaY's Avatar
    Join Date
    Jul 2002
    Posts
    140
    thanks all - this should help alot!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Whats better, C-Free or Dev C++??
    By i_can_do_this in forum Tech Board
    Replies: 10
    Last Post: 07-07-2006, 04:34 AM
  2. Resources with Dev C++ Problem (many simple problems)
    By Zeusbwr in forum Windows Programming
    Replies: 4
    Last Post: 04-06-2005, 11:08 PM
  3. New to Dev C++/<windows.h>...
    By Cilius in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2005, 01:05 AM
  4. Glut and Dev C++, Programs not Quitting?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-29-2004, 08:43 PM
  5. openGL programming - From MSVC++ to Dev C++
    By WDT in forum Game Programming
    Replies: 1
    Last Post: 03-08-2004, 05:19 PM