I am trying to write my own random number generator using OOP techniques. However, I am getting an error that I am unfamiliar with and was wondering if anyone could help me out. Below is my code for an RNG (random number generator).
//RNG.h
//Random Number Generator class definitions
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
class RNG
{
public:
RNG();//default constructor
void setRNG(double); //set RNG number
double getRNG(); //return RNG
private:
double randomNumber; //store random number
}; //end class definitions
//RNG.cpp
//Random Number Generator member-function definitions
#include <iostream>
#include <ctime>
#include <cstdlib>
#include "RNG.h"
using namespace std;
c:\users\matt\desktop\programming projects\gamepractice\gamepractice\rng.cpp(12): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>Driver.obj : error LNK2019: unresolved external symbol "class RNG __cdecl rando(void)" (?rando@@YA?AVRNG@@XZ) referenced in function _main
1>C:\Users\Matt\Desktop\programming projects\GamePractice\Debug\GamePractice.exe : fatal error LNK1120: 1 unresolved externals
int main()
{
srand (time(NULL));
RNG rando; // HERE
cout<< "Random 6 sided die roll is: "<<endl;
cout<<rando.getRNG()<<endl; // HERE
}//end main
(With the (), the compiler thinks you're providing a forward definition to a function called rando which returns a RNG value. You do need the (), of course, if your constructor takes a parameter)
And to shut up the warning add the following #define before you includes
#define _USE_32BIT_TIME_T
The default is to use a 64-bit version of time_t; this define get the code to use the old 32-bit version, which is the same size as an unsigned int.
Or you could use a cast, as you are just feeding the value to srand.