I have a problem, when I try to compile the Random.cpp, the compiler said I have these problems.
c:\documents and settings\misia\my documents\homework\cosc2406\feb7\random.cpp(30) : error C2572: 'getRandomNumber' : redefinition of default parameter : parameter 2
c:\documents and settings\misia\my documents\homework\cosc2406\feb7\random.cpp(30) : error C2572: 'getRandomNumber' : redefinition of default parameter : parameter 1
c:\documents and settings\misia\my documents\homework\cosc2406\feb7\random.h(37) : see declaration of 'getRandomNumber'
Here is my Random.h
Code:
#ifndef RANDOM_H
#define RANDOM_H
// System Include Files
#include <cstdlib>
// User Defined Include Files
// Namespaces
//using namespace std;
// Other Preprocessor Commands
// User Defined Types
// Function Prototypes
// Global Variables - Don't use unless const!
class Random
{
public:
// Public Types
// Public Attributes (State)
// Public Methods (Behavior)
//*** Constructor(s)/Destructor ***
Random();
Random( unsigned int newSeed );
//*** Accessors ***
bool operator== ( const Random& rhRandom ) const;
bool operator!= ( const Random& rhRandom ) const;
unsigned int getRandomNumber( unsigned int min = 0,
unsigned int max = RAND_MAX ) const;
unsigned int getSeed() const;
//*** Mutators ***
void reseed();
void setSeed( unsigned int newSeed );
private:
// Private Types
// Private Attributes (State)
unsigned int seed;
// Private Methods (Behavior)
//*** Accessors ***
//*** Mutators ***
};
#endif
and here is my random.cpp
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "Random.h"
using namespace std;
Random::Random()
{
reseed();
}
Random::Random( unsigned int newSeed)
{
srand(newSeed);
}
bool Random::operator ==( const Random& rhRandom ) const
{
return (rhRandom.getSeed() == getSeed());
}
bool Random::operator !=( const Random& rhRandom ) const
{
return !operator==(rhRandom.getSeed);
}
unsigned int Random::getRandomNumber( unsigned int min = 0,
unsigned int max = RAND_MAX ) const
{
int range;
int randomNum;
range = RAND_MAX - min;
randomNum = rand() % range;
return randomNum + min;
}
unsigned int Random::getSeed() const
{
return seed;
}
//*** Mutators ***
void Random::reseed()
{
srand(time(NULL));
}
void Random::setSeed( unsigned int newSeed )
{
seed = newSeed;
}
Can you guys give me some advises how to figure this problems?
Thanks a lot.