Неразрешенная внешняя ошибка или ошибка компоновщика - PullRequest
0 голосов
/ 14 февраля 2012

Я разместил 2 моих исходных файла. Я пытался выяснить, что не так в течение последних 6 часов, но я не могу найти решение этих ошибок:

1> Mainirk.obj: ошибка LNK2019: неразрешенный внешний символ "public: __thiscall pokemon :: pokemon (int, int, int)" (?? 0pokemon @@ QAE @ HHH @ Z), на который есть ссылка в функции "void _ cdecl `динамический инициализатор для« врага »(void)" (?? _Eenemy @@ YAXXZ)

1> C: \ Users \ Taylor \ Documents \ Visual Studio 2010 \ Projects \ irkling \ Debug \ irkling.exe: фатальная ошибка LNK1120: 1 неразрешенный внешний код

Mainirk.cpp и stats.h

// mainirk.cpp:

#include <iostream>

#include <string>
#include <windows.h>
#include "include/irrKlang.h"
#include <conio.h>
#include "stats.h"



#pragma comment(lib, "irrKlang.lib")
using namespace std;
using namespace irrklang;





int choose();
void charmander1();
void bulbasaur1();
void squirtle1();
void yourpokemon();
void enemypokemon();
void battle();
void bchoice();
void aichoice();



int axisx;
int axisy;
void grid();
void events();


void attack();
void defend();
int x;
int y;
int z;
int m;
int n;
void win();
void lose();
void results();
void talk1();
void travel();
int walk;
void refresh();
void enemy1();



int achoice;

pokemon enemy(1,2,1);
pokemon charmander(25,3,25);
pokemon bulbasaur(20,4,20);
pokemon squirtle(30,2,30);


int main()
{


choose();
yourpokemon();
cout<<"\nPress any key to continue.";
_getch();
system("cls");
cout<<"********************************";

cout<<"\nEverything suddenly goes dark.\n";
cout<<"\n\nYou feel a dark presense enter the area.\n";
cout<<"Your rival Chuy walks in and challenges you to a battle...\n\n\n";
cout<<"................==\n";
cout<<".............../´¯/)\n\n";
cout<<"............/....//\n\n";
cout<<".........../....//\n\n";
cout<<"...../´¯/..../´¯<\n\n";
cout<<".././.../..../..../.|\n\n";
cout<<"(.(....(....(..../.)..)\n\n";
cout<<".<......(...(.....</.../\n\n";
cout<<"..<.................<\n\n";
cout<<"....<..............<\n\n";
cout<<"......<.............<\n\n";
cout<<"\n________________________________\n";
cout<<"Press any key to continue..\n\n";
ISoundEngine* se = createIrrKlangDevice();
se->play2D("Red.mp3");
_getch(); 

system("cls");
do
{
battle();
aichoice();
_getch();
system("cls");
}
while (y>0 && m>0);
cout<<"Battle Over\n";
results();
refresh();
_getch();
system("cls");
talk1();
_getch();
do
{
grid();
travel();
events();
system("cls");
}
while (axisx!=100);
return 0;
}




int choose()
{

cout<<"Choose your pokemon!!!\n\n";
cout<<"********************************\n\n";
cout<<" Charmander has "<<charmander.hp()<<" hp and "<<charmander.dmg()<<"          damage.\n\n";

cout<<" Bulbasaur has "<<bulbasaur.hp()<<" hp and "<<bulbasaur.dmg()<<" damage.\n\n";

cout<<" Squirtle has "<<squirtle.hp()<<" hp and "<<squirtle.dmg()<<" damage.\n\n";
cout<<"--------------------------------\n\n";

cout<<"Type [a] to choose Charmander\n\n";

cout<<"Type [b] to choose Bulbasaur\n\n";

cout<<"Type [c] to choose Squirtle\n\n";
char answer;
cin>>answer;




 if (answer == 'a'||answer == 'A')
 {
 answer = 'a';
 }

 if (answer == 'b'||answer == 'B')
 {
 answer = 'b';
 }

 if (answer == 'c'||answer == 'C')
 {
 answer = 'c';
 } 




 switch (answer)
 {

if (answer =='a')
{
    case 'a': charmander1();
    enemy = squirtle;
    y= charmander.hp();
    z= charmander.dmg();
    x= charmander.bhp();

}
 if (answer == 'b')
 {
case 'b': bulbasaur1();
    enemy = charmander;
y = bulbasaur.hp();
z = bulbasaur.dmg();
x= bulbasaur.bhp();

 }
if (answer == 'c')
 {
case 'c': squirtle1();

enemy = bulbasaur;
y = squirtle.hp();
z = squirtle.dmg();
x= squirtle.bhp();

 }

 }return 0;
 }

 void charmander1()
 {
 cout<<"You have chosen the Pokemon Charmander!!!\n";
 cout<<"Charmander is a fire type!\n";
 }

 void bulbasaur1()
 {
 cout<<"You have chosen the Pokemon Bulbasaur!!!\n";
 cout<<"Bulbasaur is a grass type!\n";
 }

 void squirtle1()
 {
 cout<<"You have chosen the Pokemon Squirtle!!!\n";
 cout<<"Squirtle is a water type!\n";
 }

 void yourpokemon()
 {

 cout<<"HP is "<<y<<" and damage is "<<z;
 }



 void battle()
 {
 cout<<"\n\tStatus\t\t";
 cout<<"\n-----------------------\n";
 cout<<"Your Pokemon\tEnemy Pokemon\n";
 cout<<"HP: "<<y<<"\t\tHP: "<<m<<"\n";



 bchoice();
 }

 void bchoice()
 {
 cout<<"\n\nType 1 to attack or 2 to defend\n";

 cin>>achoice;

 if (achoice ==1)
 {
 attack();
 }
 else if (achoice ==2)
 {
 defend();
 }
 else 
 {
 cout<<"Retype your choice"<<endl;

 }
 }

 void attack()
 {
 m = m-z;
 cout<<"\nYour Pokemon attacks!";
 }

 void defend()
 {
 cout<<"\nYour pokemon defends!";
 }



 void aichoice()
 {
 if (achoice ==1)
 {
 cout<<"\nThe enemy pokemon attacks!";
 cout<<"\nPress any key to continue";
 y = (y-n);
 }


 else if (achoice ==2)
 {
 cout<<"\nThe enemy pokemon defends!";
 cout<<"\nPress any key to continue";
 }
 }


 void win()
 {
 cout<<"You have won the battle!\n";
 }

 void lose()
 {
 cout<<"You have lose the battle!\n";
 }

 void results()
 {
 if (y>0 && m <= 0)
 {
     win();
 }
 else if (m>0 && y <= 0)
 {
     lose();
 }


 }

 void talk1()
 {
 cout<<"These animals are merely pawns in a series that is about to unfold\n";
 cout<<"If i were you, I would enjoy my last days alive\n";
 cout<<"*Chuy walks away..*\n";
 }

 void travel()
 {

 cout<<"\nIt is time to travel\n";
 cout<<"Type 1 to travel North\n";
 cout<<"Type 2 to travel South\n";
 cout<<"Type 3 to travel West\n";
 cout<<"Type 4 to travel East\n";
 cin>>walk;
 if (walk ==1)
 {
     axisy++;
 }
 if (walk ==2)
 {
     axisy--;
 }
 if (walk ==3)
 {
     axisx--;
 }
 if (walk ==4)
 {
     axisx++;
 }

 }

 void grid()
 {
 cout<< "location Coordinates: "<<axisx<<","<<axisy<<"\n";

 }

 void events()
 {
 if (axisx ==5 && axisy ==10)
 {
     battle();
 }

 }

 void refresh()
 {
 m = enemy.bhp();

 }

 void enemy1()
 {
 m = enemy.hp();
 n = enemy.dmg();
 }




//stats.h

#include <iostream>
using namespace std;

class pokemon
{
int health, damage, basehp;

public: 

pokemon (int,int,int);
int hp() 
{
return (health);
}

int dmg()
{
return (damage);
}
int bhp()
{
return (basehp);
}

};

1 Ответ

1 голос
/ 14 февраля 2012

Это потому что вы объявили конструктор pokemon, который принимает 3 целочисленных параметра, но не предоставил реализацию . Вы можете указать это в заголовке

class pokemon
{
    int health, damage, basehp;
public: 
    pokemon (int _health, int _damage, int _basehp)
    :  health(_health)
    ,  damage(_damage)
    ,  basehp(_basehp) {
    }
    // ...
};

или отдельно в файле cpp, например:

pokemon::pokemon(int health, int damage, int basehp) {
    // do your initialization here...
}
...