Conversion derived - base

Nasza ocena:

3
Wyświetleń: 637
Komentarze: 0
Notatek.pl

Pobierz ten dokument za darmo

Podgląd dokumentu
Conversion derived - base - strona 1 Conversion derived - base - strona 2

Fragment notatki:

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)

Zaloguj się, aby dodać komentarz