I would suggest going with a singleton approach rather than using an extern global variable.
I would suggest going with a singleton approach rather than using an extern global variable.
ehnuh (8th November 2012)
hi thanks for the replies. what would be the edge of the singleton approach over an extern global variable?
Cleaner API, less error prone access and total control over when the variable is created and destroyed (a global variable is created before main() is executed and destroyed after main() returns). It also assures there is just one instance of the class in the whole program.
ehnuh (8th November 2012)
thanks for the info! I have tried declaring and defining the extern class variable in one pro file. Since I have multiple pro files, I want to access the CFacade FacadeObj I declared and defined. I just add the header of the FacadeObj to the cpp files found in the other pro files (I also added a header for a global shared library since it will be declared in another pro file)...I am not sure what I am still missing but when I build the whole subdirs proj, the
FacadeObj I used in the pro file is undefined. The error is "undefined reference to Facadobj"
Bookmarks