I’m pretty new to c++ and I have run into some code I am having trouble with, hopefully someone can enlighten me. It’s what I understand to be a singleton class, it’s used to hold the settings for an application. The class has a private constructor, and a private Load() method. It also instantiates itself as a private member which all seems ok I guess.
private:
MySettings(void);
MySettings(const MySettings&);
static MySettings& GetInstance();
bool Load();
private:
static MySettings mySettings;
The code within the class’s Load() method seems to be executing however, and I dont understand why. I’m not (can’t ?) calling it anywhere in my app. Is the fact the method name is “load” of any special significance? I haven’t seen any c++ guides that have talked about a speical “load” method for classes .
If someone could point my in the right direction id appreciate it, thanks
The only method that has special significance is the
mainfunction, which gets called automatically when you start the program. Load however, has no special significance. Its purpose is to avoid the loading the data when constructing the object, just in case it gets passed around everywhere (and all the copies would end up loading the data over and over).In short, no. It has no special significance. You have to be calling it somewhere. Since it’s private, you should check your constructor. It’s probably calling Load.