Ok, this is one thing which since i started using C++, ive wanted to do, but spend all my time trying to get to work that i never actually program anything.
Basically, i want to store functions and classes in different files, accordingly.
Now i understand how header files etc work. However i can never seem to get past Mr. Linker.
So in this scenario i want to store a class in another file, which has functions. For organization and for OOP.
So heres the code i have so far:
IG_Timers.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#pragma once
typedef enum { _Loop, _Move, _PosAI, _IPS, _Keypress, _Distance, _MUnits, _Animate }TimerList;
//the timers
class Timers {
public:
int GetTime(TimerList);
void SetTime(TimerList, int);
void DefineStartingTime(int);
protected:
int PreLoopTime;
int Loop;
int Move;
int PosAI;
int IPS;
int Keypress;
int Distance;
int MUnits;
int Animate;
};
|
IG_Timers.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include "IG_Timers.h"
void Timers::DefineStartingTime (int StartTime)
{
PreLoopTime = StartTime; //know when the loop begins
Loop = PreLoopTime; //define used timers
Move = PreLoopTime;
PosAI = PreLoopTime;
IPS = PreLoopTime;
Keypress = PreLoopTime;
Animate = PreLoopTime;
MUnits = PreLoopTime;
Distance = PreLoopTime;
}
int Timers::GetTime(TimerList TimerName)
{
if (TimerName == _Loop)
return Loop;
else if (TimerName == _Animate)
return Animate;
else if (TimerName == _IPS)
return IPS;
else if (TimerName == _Keypress)
return Keypress;
else if (TimerName == _Move)
return Move;
else if (TimerName == _MUnits)
return MUnits;
else if (TimerName == _PosAI)
return PosAI;
else
return -1;
}
void Timers::SetTime(TimerList TimerName, int NewTime)
{
if (TimerName == _Loop)
Loop = NewTime;
else if (TimerName == _Animate)
Animate = NewTime;
else if (TimerName == _IPS)
IPS = NewTime;
else if (TimerName == _Keypress)
Keypress = NewTime;
else if (TimerName == _Move)
Move = NewTime;
else if (TimerName == _MUnits)
MUnits = NewTime;
else if (TimerName == _PosAI)
PosAI = NewTime;
}
|
Main.cpp (just calling the functions)
1 2 3 4 5 6 7 8 9 10
|
#include "IG_Timers.h"
... ... ... ...
Timers::DefineStartingTime(100);
... ... ... ...
Timers::SetTime(_PosAI,Timers::GetTime(_PosAI));
... ... ... ...
|
The errors:
1 2 3 4 5 6
|
1>Main.cpp
error C2352: 'Timers::DefineStartingTime' : illegal call of non-static member function
see declaration of 'Timers::DefineStartingTime'
error C2352: 'Timers::GetTime' : illegal call of non-static member function
see declaration of 'Timers::GetTime'
|
Ive been playing around with static for the past few hours but what i understand is that static is the opposite from extern? Which means that i just get more errors if i use static. (so confuzzled)
Thanks in advance. I really like C++, but for some reason i will never be able to understand how to properly use multiple source files...