...
Both previous compliant solutions depend on consumers of the Employee
and Manager
types to be declared in a compliant manner with the expected usage of the class hierarchy. This compliant solution ensures that consumers are unable to accidentally slice objects by removing the ability to copy-initialize an object that derives from Noncopyable
. If copy-initialization is attempted, as in the original definition of f()
, the program is ill-formed and a diagnostic will be emitted. However, such a solution also restricts the Manager
object from attempting to copy-initialize its Employee
object, which subtly changes the semantics of the class hierarchy.
...