Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


n Help fixing error @small C++ code (classes)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
redhead
Cheater
Reputation: 0

Joined: 21 Mar 2007
Posts: 47

PostPosted: Wed Jan 02, 2008 12:25 pm    Post subject: n Help fixing error @small C++ code (classes) Reply with quote

Hey,
after a little break of programming, I wanted to "refresh" my knowledge and to programm a little Dos Game.
I just started and done a "fighter" class so far.
Seems like all is correct, I cannot find any errors @ my code, but my compiler says:
Quote:
----- Erstellen gestartet: Projekt: Klasse fighter, Konfiguration: Debug Win32 ------
Kompilieren...
fighter.cpp
Code wird generiert...
Überspringen... (keine relevanten Änderungen gefunden)
main.cpp
Verknüpfen...
fighter.obj : error LNK2005: "public: bool __thiscall Fighter::init(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int,int,int,int)" (?init@Fighter@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHHH@Z) ist bereits in main.obj definiert.
fighter.obj : error LNK2005: "public: bool __thiscall Fighter::takeDmg(int)" (?takeDmg@Fighter@@QAE_NH@Z) ist bereits in main.obj definiert.
fighter.obj : error LNK2005: "public: void __thiscall Fighter::heal(void)" (?heal@Fighter@@QAEXXZ) ist bereits in main.obj definiert.
fighter.obj : error LNK2005: "public: void __thiscall Fighter::display(void)" (?display@Fighter@@QAEXXZ) ist bereits in main.obj definiert.
F:\VisualC++\projects\Klasse fighter\Debug\Klasse fighter.exe : fatal error LNK1169: Mindestens ein mehrfach definiertes Symbol gefunden.


hmm.. here's my code:
fighter.h
Code:
#ifndef _FIGHTER_
#define _FIGHTER_
#include <iostream>
#include <string>
using namespace std;

class Fighter
{
private:
   int life;
   int maxlife;
   int mana;
   int maxmana;
   int defence;
   int dmg;
   string name;

public:
   bool init(const string&,int,int,int,int);
   bool takeDmg(int);
   void display();
   void heal();
};
#endif

fighter.cpp
Code:
#include "fighter.h"
#include <iostream>
using namespace std;



bool Fighter::init(const string& i_name,int   i_maxlife,int i_maxmana,int i_defence,int i_dmg)
{
   if(i_name.size() < 1)
      return false;
   name = i_name;
   maxlife = i_maxlife;
   maxmana = i_maxmana;
   defence = i_defence;
   dmg = i_dmg;
   return true;
}


bool Fighter::takeDmg(int a)
{
   a = a - defence;
   if(a<0)
      a=0;
   life = life - a;
   if(life<=0)
      return false;
   return true;
}



void Fighter::heal()
{
   life = maxlife;
   mana = maxmana;
}

void Fighter::display()
{
   cout<<"life: "<<life<<" / "<<maxlife<<endl;
   cout<<"mana: "<<mana<<" / "<<maxmana<<endl;
   cout<<"defence: "<<defence<<endl;
   cout<<"damage: "<<dmg<<endl;
}

main.cpp
Code:
#include "fighter.cpp"


int main()
{
   Fighter Cloud,Leon;
   Cloud.init("Cloud",1000,100,50,300);
   Leon.init("Leon",2000,100,10,165);
   Cloud.display();
   Leon.display();
   return 0;
}

I hope some1 can find the error and help me to fix it.
Thanks
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Wed Jan 02, 2008 1:19 pm    Post subject: Re: n Help fixing error @small C++ code (classes) Reply with quote

Complied and linked fine on my ICC? It's a linker issue, not a compiler issue. Your code is probably right, you're just doing something weird w/ linking. You could translate this one for me: "ist bereits in main.obj definiert." ..and the other errors too.

Code:
life: 4249904 / 1000
mana: 4250927 / 100
defence: 50
damage: 300
life: 4289732 / 2000
mana: 2089892142 / 100
defence: 10
damage: 165
Back to top
View user's profile Send private message
redhead
Cheater
Reputation: 0

Joined: 21 Mar 2007
Posts: 47

PostPosted: Wed Jan 02, 2008 1:34 pm    Post subject: Reply with quote

first: thanks for fast reply
second:
ah,sry, forgot to translate it.
Quote:

(?init@Fighter@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHHH@Z) ist bereits in main.obj definiert.

means-->
Quote:

(?init@Fighter@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHHH@Z)
is already defined in main.obj.


Quote:
fatal error LNK1169: Mindestens ein mehrfach definiertes Symbol gefunden.

means -->
Quote:
min. one sign is defined more then one time.
(this translation sux abit.^^ anyway, the only real problem is, my linker says I try to define those function's more then one time, I think..)

btw, I'm using Visual C++ 2005 Express.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites