I'm developing software that computes many different types of fractal equations and draws them to the screen using OpenGL. Different types of equations such as Complex Fractals, Cellular Automata, Iterated Function Systems, number theory, etc... and thus I have a .h and .cpp for each type of equation that I plan on implementing. Within each header is a class defining the branch of equations, this is a very simple example:
then in IFS.cpp the functions for computing the equations would follow of course. Simple, yes quite. But there is a confusion penumbra that I've meet and this is why:
Iterations = 50000;};
I create a version of this class in main.cpp, something like this:
Now, this class is accessable to main() function and main() function only... I have the GUI that needs to malliate IFSClass, I have threads that want to perverse it and other equations that use it for benchmarking etc... So the problem lies in, how do I make this globally accessable?
#include <blah blah blah.h>
IFS *IFSClass = new IFS();
// Declare all other windows and classes...
Now I know that I can use extern to make this specific class nice and usable for all other code, but it's not just this class that I need to make global. Heres the heart of my problem:
When I have a function that I pass many arguments to to initialize something, like a window:
I also need this class to be global to all other classes, to access the pointer to the window so the OpenGL functions can malliate it etc... But if I try to extern this before the start of main() all the arguments that are pointers to all different types of classes and structures that are created during the initialization of main() get FUBAR'd because they obviously havn't been created yet.
Window *mainWin = new Window("Main Window", (parent data, blah blah blah));
Now I may be making this so extremely complicated that I need to rework how I'm flowing this code entirely but this is EXACTLY what i'm trying to learn how to do. I'd like a consice review of how either articulant or slobbish my methods of global class declerations are and what better methods are and what I should learn to become a better programmer
I give this pseudo-flowchart to explain my theology of global mass-read classes and how I initialize them:
1. Create within the main() function a version of the class that I wish to make global
2. Then because I have so many global classes I create a single global class to take care of them all and pass my pointers to that declared class:
Class *NewClass = new Class(*args);
3. Then in main() I initialize my main functions and pass the pointer to the Pointers class containing all global class pointers:
4. After this is all said and done I can grab my IFS and Complex global variables from my new window class through the pointers argument, which points to another class containing global class pointers.
Pointers *pointers = new Pointers();
pointers->IFSLink = new IFS();
pointers->ComplexLink = new Complex();
Window *NewWindow = Window(blah blah blah, *pointers);