#SIngleton pattern return empty from GetInstance?

26 messages · Page 1 of 1 (latest)

edgy thistleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

stuck cape
#
Config& Config::GetInstance()
{
  static Instance instance;
  return instance;
}
#
Config& Config::GetInstance()
{
  static Config instance("./HARDCODED_PATH.config");
  return instance;
}
#

my bad

#

this syntax is a well known mechanism since C++11, it creates your instance atomically

#

why use heap allocated nonsense?

#

static local variables are basically global variables that get created only when you gall getInstance for the first time

#

and they get destroyed when main ends

#

(now, using globals is basically asking for spaghetti code but... you chose this)

#

functions are fine, global variables are not

#

you do know that there isn't a real difference between class static functions and global functions?

#

so use whatever you decide makes sense

#

code that in your constructor

#

throw there

#

use getenv() to read environment variables

#

and do your checks

#

do you know of any other functions to read enbvironment variables?

#

da hell is that

#

these are microsoft exclusive functions, they are not portable

#

do what you decide makes sense

#

ughhhhhh microsoft...

#

the only place where microsoft's insecure warnings make sense in my opinion are scanf and strcpy, all the other C functions are working just fine

#

even microsoft's _s functions can be abused if you try hard enough

edgy thistleBOT
#

This question is being automatically marked as stale.
If your question has been answered, run !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.