0

When using Polymorphism in C++, what are the important facts to know about it.

Like, for example, when casting from derived to base, what should one be aware of?

When is an upcast possible, and when not? When do you need a 'virtual' destructor and when not?

What do you need to be aware of when using pointers from base to derived objects?

There was a discussion in the C++ lounge just now about the sizeof(*this) with polymorphic types, which inspired me to ask this question.

An "obscure" fact such as this one:

"If you have a Derived that's hidden behind a Base&, then the static type is Base, while the dynamic type is Derived."

Is also the kind of things I am looking for, in this question.

Community
  • 1
  • 1
Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
  • 1
    You must be aware of the *slicing problem* http://stackoverflow.com/questions/274626/what-is-the-slicing-problem-in-c – Arafangion Aug 12 '11 at 08:08
  • 1
    Have a look at the [C++ FAQ Lite](http://www.parashift.com/c++-faq-lite/) - and specifically the sections on inheritance. Plenty of important facts are being described in detail there. – Sander De Dycker Aug 12 '11 at 08:14

1 Answers1

5

Read "Effective C++" and "More Effective C++". Answering your question here would literally require writing a small book.

Pete
  • 4,784
  • 26
  • 33