Apparently, you mean that Bar is a descendant of Foo in the class hierarchy ...
In this case, the first part can be done in two ways.
// foo_part_of_bar(bar) = foo; bar.Foo::operator =(foo); (Foo &) bar = foo; // or use a C++-style cast
(The latter may be mistaken in the exotic case, when the corresponding operator = declared virtual and is redefined in Bar . But this, as I said, is exotic.)
To complete the second part, you really do not need to make much effort.
// foo = foo_part_of_bar(bar); foo = bar; // This is called slicing
Both have very limited use in some special contexts. I wonder why you need it ...
source share