Thread: Question for Random class

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    77

    Thumbs up Question for Random class

    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.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >unsigned int Random::getRandomNumber( unsigned int min = 0,
    > unsigned int max = RAND_MAX ) const
    >{
    Since you listed your default parameter values in the declaration, I don't think you need to relist them here. So make this:
    Code:
    unsigned int Random::getRandomNumber( unsigned int min,
                                  unsigned int max ) const
    {

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    77
    thanks, it works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  2. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 06:08 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM