I want something conceptually like this in c/c++
struct first{
int a,b,c;
}my1;
struct second{
int a,b,c;
int extended;
}my2;
and somehow be able to have
my2=my1;
(meaning only copy the same parts. leaving extended untouched)
I thought of solving it as
struct second{
first first_;
int extended;
}my2;
and have
my2.first_ = my1;
but it is a bit ugly for me. is there any more clear solution for this? probably it is something like extending a structure or something?
Like that:
struct second : first
{
int extended;
second& operator=(const first& f)
{
first::operator=(f); extended = 0; return *this;
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With