开发者

What are the C++ things one should know about polymorphism [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. 开发者_StackOverflow Closed 11 years ago.

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜