Let say we need to have just one instance of some class in our project. There are couple ways of doing it.
I want to compare. Please can you review my understanding.
Another option you overlook is namespace's.
namespace xyz {
namespace {
int private_variable;
}
int get_pv() {
return private_variable;
}
}
Functionally, this is going to be similar to your option #2, but you can't accidentally "delete" this thing. You can't accidentally create an instance of it. It is just a collection of related globally accessible data and functions. You can (as in my example) even have "private" members and functions.
Of course the usage would be something like this:
int x = xyz::get_pv();