Opened 14 years ago
Closed 14 years ago
#228 closed defect (fixed)
RNG is not Singleton
Reported by: | Peter | Owned by: | Jari Häkkinen |
---|---|---|---|
Priority: | major | Milestone: | yat 0.4 |
Component: | build | Version: | trunk |
Keywords: | Cc: |
Description (last modified by )
We allow construction through the compiler generated copy constructor.
This is extra severe since the destructor destroys the instance, which is illustrated by this code snippet
RNG* rng=RNG::instance(); rng->seed_from_devurandom(); RNG* rng2 = new RNG(*rng); std::cout << rng2->name() << std::endl; delete rng2; std::cout << rng->name() << std::endl;
Change History (4)
comment:1 Changed 14 years ago by
Status: | new → assigned |
---|
comment:2 Changed 14 years ago by
Description: | modified (diff) |
---|
comment:3 Changed 14 years ago by
comment:4 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note: See
TracTickets for help on using
tickets.
There is also a flaw in that the destructor is public! Anyone can delete the content of the supposedly singleton RNG, but the instance_ is not reset to NULL. This would allow creation of new RNG singletons, but all active RNG*'s would become invalid.
All constructors should be private, and the destructor must also be private.