#ifndef RANDOMIZER_H
#define RANDOMIZER_H
void randomize(int a_seed = 0)
{
//type to hold calender time
time_t sysTime;
//Structure to hold time
struct tm timeBox;
//Read System time
sysTime= time(NULL);
//Convert calender time to tm structure
gmtime_s(&timeBox, &sysTime);
//Generate the seed
unsigned seed = timeBox.tm_sec
+timeBox.tm_min
+timeBox.tm_hour;
//feed the seed
srand(seed+a_seed);
return;
}
#endif
however i get a c2005 error when i try to declare the function
if i declare it globally, it then says the randomize function
then it says that the following
Error 1 error C2668: 'randomize' : ambiguous call to overloaded function
what should i do to fix that
it is the last thing we need to get our game running
Any particular reason you're doing all of that instead of just calling srand(time(0));? You're actually making the seeding process less random and increasing the odds of duplicate seeds. Not to mention the code is much longer (and apparently isn't even compiling).
As for your problem... there must be some other function called randomize() somewhere that's defined globally.
That's the overloaded function. Your randomize() function takes an int as argument. It should be void randomize(int);, but I don't see why you need to forward declare it in a different header file. EDIT: although I'm not sure this is the problem, since there's nothing ambiguous about the call.
Kyon wrote:
There is a randomize function defined in standard C++ (libraries)
error LNK2005: "void __cdecl randomize(int)" (?randomize@@YAXH@Z) already defined in Deal.obj
however there is no reference to randomize in my current page hence why i am unsure of how it is not working now when all i did was make and adjustment that has no bearing on that particular function
like i said before the randomize(); function itself is only called for one thing specifically so how it is effecting something it isn't even mentioned in confuzzles me
Nothing at all, it just lets you declare it in the header. Now, back in the day when compilers weren't such pros at optimizing code, the inline keyword meant that the function body was put into the place where the function call was, sort of like a macro, except that it was treated as a function.