Search code examples
c++srand

Unable to compile - scope issues


I have copied program on Simulated Annealing from a book (first result link here) and am facing the below issues on compilation, for below line in main().

srand48(tp.tv_usec);

Error on compiling with Dev-C++:

[Error] 'srand48' was not declared in this scope

The full code is at: https://onlinegdb.com/HyruMTmdN. & the relevant (trimmed version) is stated below:

#include <sys/time.h>

extern double drand48();
extern long lrand48(/*long*/);
extern int rand();
extern void srand(long seedval);



//main program
main()
{

//set random number generator
struct timeval tp;
struct timezone tzp;
gettimeofday(&tp,&tzp);
srand48(tp.tv_usec);

return 1;    
}    

Solution

  • pop() is a function and is being indexed as if it were a variable. With a quick look there is an array op which might be what’s needed here. So maybe it should be op[x] and not pop[x] in these places?

    And when looking at the original that’s how it is. So a copying error by user, should be closed.