Premium Cataclismo 86 Posted February 4, 2015 Premium Share Posted February 4, 2015 Hi, So, as the title says my client launcher is crashing when I initialize a variable. I declared a class like this: class CMyClass : public CSingleton<CMyClass> { private: int var; public: void Initialize(); } And the function Initialize(): void CMyClass::Initialize() { var = 123; } No error at compilation, but when I run the launcher it's crashing. I don't get it. Why is this happening? Link to comment Share on other sites More sharing options...
Premium Sanchez 2468 Posted February 4, 2015 Premium Share Posted February 4, 2015 You have to create at least one instance of the class before you're using singleton. Link to comment Share on other sites More sharing options...
Premium Cataclismo 86 Posted February 4, 2015 Author Premium Share Posted February 4, 2015 You have to create at least one instance of the class before you're using singleton. I don't get what you're exactly saying, but I've tried to call my function using these two ways: CMyClass::instance().Initialize(); and CMyClass mc; mc.Initialize(); Link to comment Share on other sites More sharing options...
Premium Sanchez 2468 Posted February 5, 2015 Premium Share Posted February 5, 2015 First you have to make an instance of the class: CMyClass mc; And then you can use singleton on it: CMyClass::instance().Initialize(); 1 Link to comment Share on other sites More sharing options...
Premium Cataclismo 86 Posted February 5, 2015 Author Premium Share Posted February 5, 2015 First you have to make an instance of the class: CMyClass mc; And then you can use singleton on it: CMyClass::instance().Initialize(); That's some bullshit from C++. Anyway, thanks. Link to comment Share on other sites More sharing options...
Premium Sanchez 2468 Posted February 5, 2015 Premium Share Posted February 5, 2015 Singleton is not part of C++, you can use other ways too. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now