I have 10 independent data structures that contain unsigned bytes and bit fields from different data sources. I am using C++, and was looking for a way to combine all these data structures into one data structure for the purpose of passing all the data around between different methods.For example I have an object that uses data from all 10 data structures, but I have references similar to:method(datastructure1 &d1, datastructure &d2, datastructure &d3, datastructure &d4, ...) I want to avoid this, because it is getting hard to keep track and maintain. I would prefer to have:method(superStructure &allData);I just cant think of how to combine all the data so I can still uniquely access the data from each individual structure.
Lots of independent data structures into one big one
object oriented;c++;data structures
You can do the following:Create a super class of the 10 data structures. The super class doesn't need to contain any functionality but it will need to contain the name of each one of the functions of the 10 data structures that you want to later use.Implement your 10 data structures as sub classes of the previously created super class.Count how many data items you want to send to the method you mentioned in your question and create an array with that size using the super class data type and pass the data array to the method.Iterate over the array to carry out your operations.If the function names for the 10 data structures are different you can create a variable in the super class called current_data_type to test which object is being processed in a conditional statement in step 4 from the array of objects passed.This is an example of how the code would be structured:    class SuperClass {      public:        static int current_data_type;        // add all data type specific functions        void set_values_d1 (int,double);        void set_values_d2 (int,float);        // ... add as many as necessary        double get_values_d1 (void);        float get_values_d2 (void);        // ... add as many as necessary    };    class DataType1: public SuperClass {      public:        void set_values_d1 (int,double) { /* do something */ }        double get_values_d1 (void) { /* do something */ }        // ... add all the other functions    };    int DataType1::current_data_type = 1;    class DataType2: public SuperClass {      public:        void set_values_d2 (int,float) { /* do something */ }        float get_values_d2 (void) { /* do something */ }        // ... add all the other functions    };    int DataType2::current_data_type = 2;    int arrayItems = 100;    SuperClass myDataArray [arrayItems] = {dataItem1, dataItem2, ... , dataItem100};    method(SuperClass &myDataArray, int arrayItems) {      for (int i = 0; i < arrayItems; i++) {        switch(myDataArray.current_data_type){          case 1 :            // do all computations for DataType1            break;          case 2 :            // do all computations for DataType2            break;          // create as many case statements as there are data types.        }      }    }