This is something I've been mildly wrestling with for some time.
I'm writing a simulator for an ASIC modem, which of course is composed of many components and subcomponents. My class hierarchy is up to five levels deep. One of the components represents a block of coefficients which are periodically updated and retrieved by calls from other components.
The problem: how do I make this coefficients object visible to the rest of the classes in the program?
The rules:
1. I must have only one copy of this object.
2. It must be accessible to various other objects all over the class hierarchy.
3. It has to be within one program (no RPC calls or anything like that).
4. All values initialized at startup from reading a file (no biggie).
long Host::get(int i) // return a single register
{
return (hostValues.at(i).get());
So, as you can see, all the coefficients are stored in a big array. Accessing classes include the header file to get the correct offset for the coeff they want, and make a call to get().
So...how do I make this "global?" Instantiate an object of this class in the program file?
And then, I guess I'd add an extern reference to the object in the header file? Am I on the right track?
OK, I just experimented with it, and it seems to work. I created an object called "host" in my top-level file, and in my host.h (after the class declaration), I do an external reference. That was easier than I thought. Thanks, Rocket.