I was wondering if there is a way to create a class as such:
toBeGlobal.h
Code:
#ifndef _TOBEGLOBAL_
#define _TOBEGLOBAL_
class toBeGlobal
{
public:
toBeGlobal(){
// Do Something
};
~toBeGlobal(){};
};
#endif
and initialize a toBeGlobal class in your main program as such:
main.cpp
Code:
#include <Whatevers.h>
#include "AccessingClass.h"
#include "toBeGlobal.h"
bool main()
{
toBeGlobal *test = new toBeGlobal();
exit(0);
}
where AccessingClass wants to read the initialized *test toBeGlobal class
AccessingClass.h
Code:
#ifndef _ACCESSINGCLASS_
#define _ACCESSINGCLASS_
class AccessingClass
{
public:
AccessingClass(){};
~AccessingClass(){};
void AccessFunction();
};
#endif
where AccessFunction is defined:
AccessingClass.cpp
Code:
#include "AccessingClass.h"
void AccessingClass::AccessFunction()
{
// Malliate whatever's in *test toBeAccessed class
}
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 headers
- Please and thank you!