Passing along function parameters
Hey!
Just a note to start, this is cross-posted from gamedev.
I've started theorizing a timer class. I will be using SDL's timer functionality, and basically what I would love to do is have my program start having SDL tick away once I initialize the class, and then let the user start a new timer (not an SDL timer), and end it, allowing me to just compare how many ticks there were from SDL_GetTicks() at the beginning and the end of the user timer.
Here's what I have:
Code:
#ifndef SGE_TIMER_CLASS
#define SGE_TIMER_CLASS
struct timer
{
Uint32 startTime;
Uint32 endTime;
}
class timer
{
public:
timer();
~timer();
void start(string tstartName);
int end(string tendName);
private:
};
timer::timer()
{
SDL_GetTicks();
}
timer::~timer()
{
}
void timer::start(string tstartName)
{
// This is where we run into problems
// were actually creating a new timer with the name 'newtName'
// not newtName's variable set above
if(tstartName == NULL)
{
timer tstartName;
tstartName.startTime = SDL_GetTicks();
}
else
{
// log error of timer's existance
}
}
int timer::end(string tendName)
{
// Again, we have naming problems here
// pertaining to the variables used for the name
if(tendName != NULL)
{
timer tendName;
Uint32 startTicks = tendName.startTime;
tend.endTime = SDL_GetTicks() - ticks;
}
else
{
// Again, log error of timer's existance
}
}
#endif
Thing is, as you can see by my comments, I want to create a new type out of my structure with the name passed in the function, but it's set up to use the variables name!
What do I need to do to use the variable passed as the name for the new structure?
Thanks! Hopefully everybody can understand my stupidity :)
FlyingIsFun1217
PS: For those that aren't familiar with SDL, SDL_GetTicks() returns a 32 bit unsigned integer.