I’m developing a little programme to implement some sorts algorithm in C++. I’ve decided to define a little object for this task which has some generators and sort functions. But, in randomGenerator() function, it gives an “error C3861: ‘rand’: identifier not found”. Even I include ctime lib, it does not go away and I think there is no reason to get this error…
Here is the code:
SortLib.h
#ifndef SORTLIB_H
#define SORTLIB_H
#include<ctime>
class SortLib
{
public:
void randomGenerator( int* userArray, int upperLimit);
void orderedGenerator( int* userArray, int upperLimit );
void reverseOrderedGenerator( int* userArray, int upperLimit );
void insertionSort( int* userArray, int upperLimit );
void selectionSortSort( int* userArray, int upperLimit );
void bubbleSort( int* userArray, int upperLimit );
void mergeSort( int* userArray, int upperLimit );
};
#endif
SortLib.cpp
#include "SortLib.h"
void SortLib::randomGenerator( int* userArray, int upperLimit)
{
for(int i=0; i<upperLimit; i++ )
{
userArray[i] = ( rand() % upperLimit );
}
}
Do you have any idea about what’s going on? Thanks!
Do this at the start of your code.
Rand function is included in the C Standard General Utilities Library.