I was wondering if there is a way to create a class as such:
toBeGlobal.h
and initialize a toBeGlobal class in your main program as such:Code:#ifndef _TOBEGLOBAL_ #define _TOBEGLOBAL_ class toBeGlobal { public: toBeGlobal(){ // Do Something }; ~toBeGlobal(){}; }; #endif
main.cpp
where AccessingClass wants to read the initialized *test toBeGlobal classCode:#include <Whatevers.h> #include "AccessingClass.h" #include "toBeGlobal.h" bool main() { toBeGlobal *test = new toBeGlobal(); exit(0); }
AccessingClass.h
where AccessFunction is defined:Code:#ifndef _ACCESSINGCLASS_ #define _ACCESSINGCLASS_ class AccessingClass { public: AccessingClass(){}; ~AccessingClass(){}; void AccessFunction(); }; #endif
AccessingClass.cpp
I know that I can pass a pointer to the *test class in the call of AccessingClass, but I don't want to do that. I find it very sloppy and I was hoping that there is a better way of doing it with headersCode:#include "AccessingClass.h" void AccessingClass::AccessFunction() { // Malliate whatever's in *test toBeAccessed class }
- Please and thank you!



LinkBack URL
About LinkBacks


