2012-02-14 26 views
0

私は2つのソースファイルを投稿しました。私は最後の6時間何が間違っているかを調べようとしていましたが、これらのエラーの解決策を見つけることができません:未解決の外部またはリンカーエラー

1>エラーLNK2019:未解決の外部シンボル "public:__thiscall pokemon :: pokemon "void _ cdecl`敵の動的初期化子 '(void) "(?? _Eenemy @@ YAXXZ)

(" int、int、int)

1> C:致命的なエラーLNK1120:\ユーザーは\デバッグ\のirkling.exeをirkling \プロジェクト\ Visual Studioの2010 \テイラー\ドキュメント\ 1つの未解決の外部

Mainirk.cppをして

をstats.h

//mainirk.cpp:あなたは3つの整数パラメータを取りますが、その実装を提供していませんでしたコンストラクタpokemonを宣言しているため

#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

です。

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

私が間違ってそれを入れている必要があります。このようにあなたは、ヘッダーのcppファイル内

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

または別々にインラインでそれを提供することができますどちらか。私は同じエラーが発生し続けます。私の見出しにどのくらい正確に見えるでしょうか? – Chuy

+0

@Chuyヘッダーにコンストラクターを定義する方法の例を含めるように答えを編集しました。 – dasblinkenlight

+0

これを今これに変更しました。どのようにしてmain.cppがsquirtle.hp()を出力できるようにするのですか? ? canotがhpを認識していると言います。もう古いエラーはありませんので、私はこの仕事をより近づけることを知っています。 #include using namespace std; クラスポケモン { int health、damage、basehp; 公共: ポケモン(int型馬力、int型DMG、int型BHP) \t:健康(HP) 、損傷(DMG) 、basehp(BHP){ \t \t \t \t} // ...} ; – Chuy