I guess this a classic, but in my case I have constraints that should simplify the problem.
It's just that I'm getting some struct A at the input of my module, and want to add a few attributes to it. So I create a struct B which extends A, and add what I need.
Now whenever I call a method that expects a B but I feed it an A, the compiler ain't happy : A objects may not be Bs, like all felines are not lions.
But in my case, I swear that all As are Bs, albeit with less attributes. Attributes that are not found can be reported as uninitialized, that's fine, I also swear I will never call an attribute before initializing it. Basically, first thing I do when getting A objects as input is to fill the remaining B attributes, which are calculated based on A attributes. I just don't want to make copies of the As I get into Bs just to add a few attributes, because then the attributes of the As would be copied in memory. I'm not gonna ever modifiy those original attributes of A either, I'm just gonna use them to calculate derived attributes, and then pass around and work on B objects with A attributes and derived attributes.
Example :
From common, project-wide header :
struct Rectangle {
// Side lengths
int a,b;
}
From local header :
struct LocalRectangle : Rectangle {
int area;
}
void updateModule(Rectangle inputRect);
From local source :
void updateModule(Rectangle inputRect) {
LocalRectangle r = (LocalRectangle)inputRect;
r.area = r.a*r.b;
// More processing ...
}
How do I do this ?
Thanks in advance,
Charles