how to assign base class object to a derived class object?
问题 Assuming I have a base class A and publicly derived class B, how should I assign A object to the A base class subobject of B? class A {...}; class B : public A {...}; A a(..); B b(..); static_cast<A&>(b) = a; ??? Is that doable without writing assignement operator for B? Are there any potential problems with casting b to A&? Is that standard conformant? 回答1: Writing another answer to demonstrate why and how assign a base class object to a derived class object. struct TimeMachineThing_Data { .