Player.h
#ifndef_PLAYER_H_
#define _PLAYER_H_
class Player {
private:
char * id;
char * job;
int level;
int hp;
public:
void setId(char * id);
void setJob(char * job);
void setLevel(int level);
void setHp(int hp);
};
#endif
Player.cpp
#include <iostream>
#include "Player.h"
using namespace std;
//default constructor
void Player() {
cout << "Create an object.";
}
//Initial value generator (parameter)
void Player(char * id, char * job, int level, int hp) {
setHp(10); // Error output here! (Identifier "setHp" is not defined.)
}
//Setter
void Player::setId(char * id) {
this->id = new char[strlen(id) + 1];
strcpy_s(this->id, strlen(id) + 1, id);
}
void Player::setJob(char * job) {
this->job = new char[strlen(job) + 1];
strcpy_s(this->job, strlen(job) + 1, job);
}
void Player::setLevel(int level) {
this->level = level;
}
void Player::setHp(int hp) {
this->hp = hp;
}
I'm trying to call the function defined below in the constructor, but I can't find itcrying Maybe it's because I'm doing Java, but I'm so worn out! Help!
c++ header-files
If you define a member function outside of the class,
class name::method name (...)
{
}
You have to write with.
For constructors,
Player::Player(){
// Come on, come on
Please write it like this~
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
578 Understanding How to Configure Google API Key
611 GDB gets version error when attempting to debug with the Presense SDK (IDE)
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.