Classes/Functions
Working on creating a class with methods, using functions i have to get and display info
im getting an error that says "error: no matching function for call to 'Player::input()' on line 24
i appreciate any input
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <iostream>
using namespace std;
class Player{
private:
string name;
int score;
int health_status;
string weapon;
int strength;
public:
void input(string name,int score,int health_status,string weapon,int strength); //you may chose to leave empty, or add parameters
void output();
};
int main()
{
Player info;
info.input();
info.output();
return 0;
}
void Player::input (string N_ame, int S_core, int H_ealth_status, string W_eapon, int S_trength){
cin >> N_ame;
cin >> S_core;
cin >> H_ealth_status;
cin >> W_eapon;
cin >> S_trength;
name = N_ame;
score = S_core;
health_status = H_ealth_status;
weapon = W_eapon;
strength = S_trength;
}
void Player::output(){
cout << name << " " << score << " " << health_status << " " << weapon << " " << strength;
}
| |
Edit: You don't have the <string> header included, the compiler would have said something about that.
the input function requires arguments, you didn't supply any.
You should make the parameters const, with strings passed by reference:
31 32 33 34 35 36
|
void Player::input (const string& NameIn,
const int ScoreIn,
const int Health_statusIn,
const string& WeaponIn,
const int StrengthIn )
{
| |
I changed the naming convention to something less annoying IMO, you will have to change the names inside the function to match.
Another Idea is to use a constructor for this purpose, I leave it to you to research how to use a memeber init list.
Last edited on
Topic archived. No new replies allowed.