2016-04-05 8 views
-4

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)

+3

İ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. –

+0

yığın taşması, tüm kodu girmeme izin vermiyor –

+0

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

cevap

0

derleme yaptığı kod

void VillianPunch(Hero *hero, Villian *villian){ 
    hero -> health -= villian -> punch; 
    std::cout << villian -> name << ": take this(punch)" << std::endl; 
} 
void VillianKick(Hero *hero, Villian *villian){ 
    hero -> health -= villian -> kick; 
    std::cout << villian -> name << ": take this(kick)" << std::endl; 
} 
void HeroPunch(Hero *hero, Villian *villian){ 
    villian -> health -= hero -> punch; 
    std::cout << hero -> name << ": take this(punch)" << std::endl; 
} 
void HeroKick(Hero *hero, Villian *villian){ 
    villian -> health -= hero -> kick; 
    std::cout << hero -> name << ": take this(kick)" << std::endl; 
} 

The main functions

; hata mesajı bağlayıcıdan. (Bağlayıcının neden şikâyet ettiği sembolü bulamadığı konusunda, bu kod, Oyun-simülasyon kütüphanesi ve Standart Kütüphane arasındaki etkileşimde muhtemelen bir yerdedir ve ben de spekülasyon yapmam.)