I've come across some code looking like the following -
class A
{
public:
A();
~A();
}a;
This occurs in in foo.cpp
, and there is a foo.hpp
where class A sees no use at all. This is the only usage of this class in an entire code base. The instance a
sees no use anywhere inside foo.cpp
.
When is a
created and destroyed?
Since it's been marked as a duplicate I'll highlight/extend the bit that makes it not a duplicate -
Does this style of instantiating a class alongside its definition have a name?
There is a comment alongside this class that describes it as a singleton. Is that correct? I realize it doesn't follow the GoF implementation of a singleton, but this is only instance of A that can exist correct (given that it's not used anywhere else inside of foo.cpp
)?