I have read some of the wikis in StackOverflow, and I've written the following header file for my Randomizer class:
class Randomizer
{
public:
static Randomizer& instance(void);
int nextInt(int);
int nextInt(int, int);
int die(int);
double nextDouble(void);
char randomChar(const std::string&);
private:
Randomizer(void) {};
/* No implementation of the following methods */
Randomizer(Randomizer const&);
void operator= (Randomizer const&);
};
I have also implemented some of the methods inside of the class, like nextInt and such.
I am unsure about how to make an instance of this Singleton class, i.e. how to write a test drive in main()?
I tried:
int main()
{
Randomizer r;
r = Randomizer::instance();
}
Compiler says a few errors:
In file included from Randomizer.cpp:11:0:
Randomizer.h: In function ‘int main(int, char**)’:
Randomizer.h:22:9: error: ‘Randomizer::Randomizer()’ is private
Randomizer(void) {};
^
Randomizer.cpp:56:16: error: within this context
Randomizer r;
^
In file included from Randomizer.cpp:11:0:
Randomizer.h:25:14: error: ‘void Randomizer::operator=(const Randomizer&)’ is private
void operator= (Randomizer const&);
^
Randomizer.cpp:57:7: error: within this context
r = Randomizer::instance();
^
Thanks for help.