I have 2 structures that have 90% of their fields the same. I want to group those fields in a structure but I do not want to use the dot operator to access them. The reason is I already coded with the first structure and have just created the second one.
before:
typedef struct{
int a;
int b;
int c;
object1 name;
} str1;
typedef struct{
int a;
int b;
int c;
object2 name;
} str2;
now I would create a third struct:
typedef struct{
int a;
int b;
int c;
} str3;
and would change the str1 and atr2 to this:
typedef struct{
str3 str;
object1 name;
} str1;
typedef struct {
str3 str;
object2 name;
} str2;
Finally I would like to be able to access a,b and c by doing:
str1 myStruct;
myStruct.a;
myStruct.b;
myStruct.c;
and not:
myStruct.str.a;
myStruct.str.b;
myStruct.str.c;
Is there a way to do such a thing. The reason for doing this is I want keep the integrety of the data if chnges to the struct were to occur and to not repeat myself and not have to change my existing code and not have fields nested too deeply.
RESOLVED: thx for all your answers. The final way of doing it so that I could use auto-completion also was the following:
struct str11
{
int a;
int b;
int c;
};
typedef struct str22 : public str11
{
QString name;
}hi;