I am quite new to C++, so if there is a easier way to get what I want, feel free to tell me...
I've got a header containing constants I need to include everywhere in my code to use them in equations. Stuff like temperature and pressure.. Before I was using a single object with a constant mass.
real massObject = 7.35619e-25;
Now I want to have more than one mass to be able to use more objects. So I tried to define Elements of an array I created.
const int numObjects = 1;
double vmassObject[numObjects];
vmassObject[0] = 7.35619e-25;
Then I found out that it was not possible to define every Element outside a function but I don't want to use a function because I would have to call it everytime. Also passing is no option. Is there a way to define the elements globally?
Thanks
static, so that it will be initialized only once throughout the lifetime of your program (and not every time the function is called). You can further pass an input argument to the function, telling it which element in the array you want it to return. Thus, you keep this array encapsulated under a narrow interface, with an access level of your choice (here, I have described a simple interface with read-only access level). In addition, if you want to optimize furthermore, you can declare the functioninline.