To tylko jedna z 2 stron tej notatki. Zaloguj się aby zobaczyć ten dokument.
Zobacz
całą notatkę
Conversion derived - base The conversion from ”pointer to derived” to ” pointer to base” is allowed and automatic without explicit cast operator … if inheritance was public - Why only one-way conversion? - Example person o(…); adult d(…); child x(”Willy”, ”Smith”, &o, &d); x.print_all() // does not print ID_card of d (daddy) The conversion from ”pointer to derived” to ” pointer to base” is allowed and automatic without explicit cast operator … if inheritance was public - Caution!: deleting converted pointer person *o=new adult("aa", "bb", "cc"); delete o; // does not free the third field - Solution?: virtual destructors. A „reference to base class” may refer to object of derived class if the inheritance was public Notes on conversions of pointers and references: - The conversions are transitive - Allowed only with public inheritance (to avoid a backdoor access to inherited private/protected fields)
... zobacz całą notatkę
Komentarze użytkowników (0)