github Havuzu: https://github.com/d-parkinson/C-practice-file.gitNeden onun sözdizimsel doğru programı XVII IDE ile derlenmez?
Created 4/04/2016 by Darren Parkinson. This is a two player simulation fight game between two characters: a Villian and a Hero Each Character has four features respectively: Name(string), health(integer), kick(integer), punch(integer)
#include <iostream>
#include <string>
Superclass holding details of regarding the features of the characters
class Character{
public:
std::string name;
static int health;
int kick;
int punch;
Character(std::string name, int health, int kick, int punch){
this -> health = health;
this -> name = name;
this -> kick = kick;
this -> punch = punch;
}
~Character(){}
};
Subclass displaying features of heroes
class Hero : public Character{
public:
Hero(std::string name, int health, int kick, int punch) : Character(name, health, kick, punch){
std::cout << name << ": Joker giving trouble again" << std::endl;
}
~Hero(){}
};
Subclass displaying features of villians
class Villian : public Character{
public:
Villian(std::string name, int health, int kick, int punch) : Character(name, health, kick, punch){
std::cout << name << ": Hey there hehehe" << std::endl;
}
~Villian(){}
};
Functions illustrating actions between both villain and hero classes
int main(void){
Hero *batman;
Villian *joker;
joker = new Villian("Joker",1000,90,63);
batman = new Hero("Batman",1100,93,60);
std::cout << "Fight!!!" << std::endl;
Do function simulating the fight between Villian and Hero
do{
HeroPunch(batman, joker);
VillianPunch(batman, joker);
VillianKick(batman, joker);
HeroKick(batman, joker);
if(batman -> health <= 0)
std::cout << joker -> name << ": You won't catch me today hehehe" << std::endl;
else if(joker -> health <= 0)
std::cout << batman -> name << ": How many times do I have to defeat you" << std::endl;
}while((batman -> health > 0) & (joker -> health > 0));
delete joker;
delete batman;
return 0;
}
I'm a new c++ programmer, practicing with git and stack overflow
Error messages below:"Character::health",referenced from:
VillianPunch(Hero*, Villian*) in Game-simulation.o
VillianKick(Hero*, Villian*) in Game-simulation.o
HeroPunch(Hero*, Villian*) in Game-simulation.o
HeroKick(Hero*, Villian*) in Game-simulation.o
_main in Game-simulation.o
Character::Character(std::__1::basic_string, std::__1::allocator >, int, int, int) in Game-simulation.o ld:
symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
İhtiyacınız var Derleyici hata mesajlarını sorunuza dahil etmek. Ayrıca, gerçek kod, yorumları HTML'ye işleyen bir şeyden çok daha iyi olurdu. –
yığın taşması, tüm kodu girmeme izin vermiyor –
Sorunuz derleyici hatalarıyla ilgiliydi. En azından, söz konusu hataları söz konusu hatalara ve ilgili kod satırlarına eklemeniz gerekir. – LodeRunner28