L
Leon Pollak
Hello, all.
I have the structure
struct tStruct {
int a;
int b;
int c;
.....
};
and a lot of working code based on this structure.
Now comes the change, that makes exactly the same processing in all derived
objects, with the only exception: no element 'b' is allowed (the structure
arrives from several communication channels).
The only solution which came to me was:
template <int T> struct tStruct {
int a;
int b[T];
int c;
.....
};
which will eliminate 'b' in the case of declaration:
tStruct<0> Object;
But this mans that the existing case
tStruct<1> Object;
requires all code rewriting to change
Object.b = 1;
to the new one:
Object.b[0] = 1;
Obviously, very not desirable rework...
Is there some more elegant way to solve this?
I have the structure
struct tStruct {
int a;
int b;
int c;
.....
};
and a lot of working code based on this structure.
Now comes the change, that makes exactly the same processing in all derived
objects, with the only exception: no element 'b' is allowed (the structure
arrives from several communication channels).
The only solution which came to me was:
template <int T> struct tStruct {
int a;
int b[T];
int c;
.....
};
which will eliminate 'b' in the case of declaration:
tStruct<0> Object;
But this mans that the existing case
tStruct<1> Object;
requires all code rewriting to change
Object.b = 1;
to the new one:
Object.b[0] = 1;
Obviously, very not desirable rework...
Is there some more elegant way to solve this?