Server Help

Bot Questions - C++ Linker error... I don't get it

Samapico - Sun Apr 29, 2007 5:57 pm
Post subject: C++ Linker error... I don't get it
I posted this on ssforum ... figured I'd post it here too, cause it's really blocking me now and I can't do anything >=(

----------------

I just started playing around with Merv stuff... but now I'm getting an error from the linker when it's building the exe:

Error 1 error LNK2019: unresolved external symbol "private: class timerms __thiscall botInfo::testtimer(void)" (?testtimer@botInfo@@AAE?AVtimerms@@XZ) referenced in function "public: void __thiscall botInfo::gotCommand(struct Player *,struct Command *)" (?gotCommand@botInfo@@QAEXPAUPlayer@@PAUCommand@@@Z) command.obj

The bug comes from the line:
Code: Show/Hide
int timervalue = testtimer().ReadTimer();

ReadTimer() is a int function of the class 'timerms'

I get linker errors anytime I call a non-void method within that class... wtf... What am i doing wrong?


Here's the relevant code... If you notice anything weird or stuff I shouldn't be doing, please tell me, even if it's not related to the problem... It's the first time I do C++

spawn.h
Code: Show/Hide
[...]
#include "timerms.h"

[...]

class botInfo
{
   // Put bot data here
   timerms testtimer();
[...]



commands.cpp
Code: Show/Hide
#include "spawn.h"
[...]
void botInfo::gotHelp(Player *p, Command *c)
{
[...]
int timervalue = testtimer().ReadTimer(); //Could be any other non-void call, it does the same error
[...]




timerms.h
Code: Show/Hide
#include "spawn.h"

#define NOT_INITIALIZED -1

class timerms
{
   int starttime;
   int pausetime;
   
public:
   timerms()
   {
      ResetTimer();
   }
   bool isrunning;
   bool ispaused() { return (!isrunning && pausetime != NOT_INITIALIZED);}
   void StartTimer(int starttime);
   void StartTimer();
   void PauseTimer(int pausetime);
   void PauseTimer();
   void ResumeTimer(int resumetime);
   void ResumeTimer();
   void ResetTimer();
   int ReadTimer();

   ~timerms()
   {
   }
};


timerms.cpp
Code: Show/Hide
#include "spawn.h"

[...]

int timerms::ReadTimer()
{
   return 0; //No matter what code in here, gives the same error
}




I searched on Google and the only thing I found was about some libraries and stuff... but I'm not using any API or external dll or whatever...

Oh, and this is with Visual Studio 2005 pro
Mine GO BOOM - Sun Apr 29, 2007 6:39 pm
Post subject:
Where is the following code? It is looking for a definition of the function, but cannot find it.
Code: Show/Hide
timerms botInfo::testtimer()
{
   //Stuff
}

My guess is you wanted to define that as a variable instead of a function inside your class.
Samapico - Sun Apr 29, 2007 6:41 pm
Post subject:
testtimer is an instance of 'timerms' class

maybe I'm doing something wrong though...
But it works for all void functions... EDIT: hm no it doesn't, I thought it did for some reason... hmmm

Code: Show/Hide
class botInfo
{
   // Put bot data here
   timerms testtimer();


my declaration is probably wrong...

when calling functions of the class, should it be like:
testtimer().ResetTimer();
or
testtimer.ResetTimer();
?
For now it only lets me use the first way... which I don't think is right so.. emm..


EDIT:
OK got it lol

hmmm ok since I was declaring it as a class member, I can't call the constructor with it or anything, so it doesn't need the ()'s... mhm I seeeeeeee

thanks icon_smile.gif
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group