C++ Define elements of array outside function -
i quite new c++, if there easier way want, feel free tell me...
i've got header containing constants need include everywhere in code use them in equations. stuff temperature , pressure.. before using single object constant mass.
real massobject = 7.35619e-25;
now want have more 1 mass able use more objects. tried define elements of array created.
const int numobjects = 1; double vmassobject[numobjects]; vmassobject[0] = 7.35619e-25;
then found out not possible define every element outside function don't want use function because have call everytime. passing no option. there way define elements globally?
thanks
you can initialize array:
double vmassobject[numobjects] = { 7.35619e-25 };
on related note, can't put in header file include in multiple source files. that's because array defined multiple times, , can have 1 definition in program.
in header can declare array:
extern double vmassobject[numobjects];
then put definition (with initialization) in single source file.
Comments
Post a Comment