is it safe to do something like this:
class Base { public: int x; };
class Derived : public Base { public: int y; };
Base b;
Derived d;
b.x = 1;
d.x = 2;
d.y = 3;
std::swap(b,d);
At this point is it guaranteed that the derived info d.y is still valid? In other words I am only swapping the base object but the derived data is still valid, correct? Also, is this considered slicing?
EDIT: In comments it's been pointed out this won't compile. What's the best way to swap the base data in d with b? Keep in mind b is obviously a lot more complicated then I put in my example.