Suppose I have:
class Foo {
...
};
class Bar : public Foo {
...
};
Foo foo;
Bar bar;
Is there anyway to do the following:
foo_part_of_bar(bar) = foo;
foo = foo_part_of_bar(bar);
?
Thanks!
Assuming you meant class Bar : public Foo
, the following should work.
For foo_part_of_bar(bar) = foo;
*(static_cast<Foo *>(&bar)) = foo;
For foo = foo_part_of_bar(bar);
foo = bar;
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