Singleton class
-
Hi, I have a singleton class. I need to access the static getInstance() from another file. The singleton class is defined in another file. I suppose the static variables and methods have file access. Thanks, Venkat SR
-
Hi, I have a singleton class. I need to access the static getInstance() from another file. The singleton class is defined in another file. I suppose the static variables and methods have file access. Thanks, Venkat SR
Add the #include diective in the .cpp where u want to create the singleton class.
-
Add the #include diective in the .cpp where u want to create the singleton class.
#include "singletonFile.h" Single one ; if(one == NULL) one = Single::getInstance(); else return one;
-
Add the #include diective in the .cpp where u want to create the singleton class.
Hi, Thanks for reply, Class B is singleton. This has static getInstance(). I want to access getInstance() of Class B in Class A. Class B header is included in Class A. When i do this, it gives linker error LNK2001 unresolved external symbol getInstance(). This error occurs for other non-static functions of Class B, when called from Class A. Thanks, Venkat SR
-
Hi, Thanks for reply, Class B is singleton. This has static getInstance(). I want to access getInstance() of Class B in Class A. Class B header is included in Class A. When i do this, it gives linker error LNK2001 unresolved external symbol getInstance(). This error occurs for other non-static functions of Class B, when called from Class A. Thanks, Venkat SR
the format is classB::getInstance. Note that you have to prefix the class name than :: than getInstance. If you are doing that, double check your includes. Make sure you haven't accedently #IFed the class out somehow.