Currently I have (a much bigger version of) the code below in my main cpp file:
struct myData
{
int dataCodeNum;
char* dataName;
}
myData arrayOfData1[]={
{ 1, "Data 1.1" },
{ 2, "Data 1.2" },
{ 3, "Data 1.3" },
};
myData arrayOfData2[]={
{ 1, "Data 2.1" },
{ 2, "Data 2.2" },
{ 3, "Data 2.3" },
};
I need the struct definition and the arrays of structs to be accessible to many functions and classes throughout my program, but I was hoping to get them out of the main cpp interface file.
I was thinking about plopping the whole thing in a header file and then #include-ing that file to all other files that would use these arrays of structs, but that just seems wrong to have objects in the header file... I mean, when you have a class, you only put the class definition in the header file, and your objects get declared in some cpp file...
Thus far everything I have read or looked up has shown how to create structs, but I am having a hard time finding any information about putting these structs (and/or their objects) in separate files.
Thanks.
struct myData
{
int dataCodeNum;
char* dataName;
}
myData arrayOfData1[]={
{ 1, "Data 1.1" },
{ 2, "Data 1.2" },
{ 3, "Data 1.3" },
};
myData arrayOfData2[]={
{ 1, "Data 2.1" },
{ 2, "Data 2.2" },
{ 3, "Data 2.3" },
};
I need the struct definition and the arrays of structs to be accessible to many functions and classes throughout my program, but I was hoping to get them out of the main cpp interface file.
I was thinking about plopping the whole thing in a header file and then #include-ing that file to all other files that would use these arrays of structs, but that just seems wrong to have objects in the header file... I mean, when you have a class, you only put the class definition in the header file, and your objects get declared in some cpp file...
Thus far everything I have read or looked up has shown how to create structs, but I am having a hard time finding any information about putting these structs (and/or their objects) in separate files.
Thanks.
Comment