Re:C++ Frequently Questioned Answers (2009)
by captainmuon on Sunday January 23, 2022 @12:29PM
(#30048128)
No I don't know Rust very well, I really should put in some time to learn it properly! I did a bit of GUI programming in the past, and felt there is a bit of impedance mismatch with Rust there. And the kind of subtle mistakes with ownership and reference cycles you tend to make in C++, but discover when you move to unique_ptr: Rust also ruthlessly uncovers them, but I guess I need more experience how to solve them.
You put your dynamic components into references and smart pointers of the form Box<dyn Component>, where Component is a so-called “object-safe trait” (which is exactly what you’d call an interface in the OO world). These traits can inherit from each other, and you can upcast a Box<ConcreteType> into a Box<dyn Interface> into a Box<dyn ParentInterface>.