I'm having a bit of a problem with how to code something.
Here is how it is in my head.

I want a function which is not part of a class to access members of that class, so I want to make the class global.
I have done this with other classes by the normal method of extern Class instance; In a global.h file and Class Instance; In a global.cpp file.

The problem arises because the class instance needs to be instantiated after other data is made available globally after another non class function has logged into website, and returned configuration data.
So when my program is launched the global class does not have the data to use.

I'm hoping someone might have some suggestion on how to properly navigate my problem with correct procedure, that is of course if you can understand my ramblings.

Thank you for taking the time to read.

Recommended Answers

All 3 Replies

I've stopped the global class being instantiated by changing it to a pointer to class type.

But now I need to intantiate an instance of the class which can be accesses via that pointer, which I'm also having trouble getting my head around.

So when my program is launched the global class does not have the data to use

Then I suspect you need to reorginze the logic of your program. Function foo() can't do it's job if the data doesn't exist yet.

Indeed, I could not think of another more generic and maintainable way to do it, and my solution feels a bit hackish even if it does the job.

As I said, I made a global pointer instead of global instance, then after login, created an instance and assigned reference of it to global pointer.

I'm not altogether happy with it, but I'll mark this as solved since the immediate problem is.

Thanks for input Ancient Dragon.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.