#Singleton Implamentation
1 messages · Page 1 of 1 (latest)
when the constructor is called, the singleton is assigned to whatever object is being constructed (this)
i understand that part, though this is the line that i can't wrap my head around Texture_Manager* Texture_Manager::m_s_instance = nullptr;
why is there Texture_Manager* data type before an already declared variable?
m_s_instance is the singleton
It's nullptr at start to make sure it's only constructed once
That assert in the constructor makes sure that the program crashes when the constructor is called twice
uh
it's a c++ moment ig
does it do anything outside of assigning the member variable a nullptr value?
oh lol, thank you
is this like a static variable convention then?
where you need to specify the data type of the static var before assigning it it's first value?
yes i think
that makes a lot more sense then, thanks once again!
ye but that makes sense with a method since it has return type
but var does not need return type
it's prolly some static shananaghas then
m_s_instaanec is a member of the class. Only it's a static member, so there's one instance of it for the class, rather than one instance for each object of that class type.
bruh its been 2 months
this static pointer implementation is not thread safe by the way
class TextureManager
{
public:
static TextureManager& instance()
{
static TextureManager tm;
return tm;
};
No mucking around with pointers.
No worries about lifetime.