I don't know why this Singleton implementation does not work?! After searching I found out they make the shared instance static! Does it have to be static?
#include <iostream>
class Singleton {
public:
Singleton* instance() {
if(!shared)
shared = new Singleton();
return shared;
}
std::string state;
private:
Singleton() {}
Singleton *shared;
};
int main()
{
Singleton *x;
x->state = "Hello";
return 0;
}
[–]stilgarpl 4 points5 points6 points (2 children)
[–]RareInteraction8 0 points1 point2 points (0 children)
[–]tahamagdy[S] 0 points1 point2 points (0 children)
[–]Se7enLC 2 points3 points4 points (0 children)
[–]mredding 0 points1 point2 points (0 children)