Loading

The way I've loaded data so far has been through functions, and passing a good amount of variables to a lot of functions (very tedious, although incredibly efficient). I dont want to do this. Is there a way to store these variable on a global level so i can write a class the will sort through it and return independent values for any function in my program?

Im learning on my own. Thank you.
You could organize your data into structs and then pass the structs into the functions.

Or...

You could take the object oriented approach and make classes with member variables and methods (functions). Member variables are global to that class and can be used by any of the member functions without cluttering the rest of your code.
Interesting. I will try that.

How would i pass it on to other functions through a header file though?
Last edited on
ok, I'm having problems passing the data structure to a function through a header file.

Can somone please give me the correct syntax so I know what I'm doing? Thank you for your time.

I could not find the answer with a search... :'(
Declare your struct with whatever name and with whatever members:
1
2
3
4
5
6
7
8
struct MySetOfData
{
    int a;
    int b;
    float f;
    double d;
    short something_else;
};


Pass this data into a function:
1
2
MySetOfData data;
SomeFunction(data);


In the function definition:
1
2
3
4
5
6
7
void SomeFunction(MySetOfData& data)
{
    data.a = 0;
    data.b = 1;
    data.f = a + b;
    // Whatever else you want...
}




@ stewbond
You forgot about the part where I should declare it in a header file.
Thank you though, i found a forum topic after a bit more searching and now data structures are my new best friend!! Gosh this will make things so much more freaking easier!
Topic archived. No new replies allowed.