Source |
CodingSec |
Identifiant |
9409 |
Date de publication |
2016-08-29 18:00:49 (vue: 2016-08-29 18:00:49) |
Titre |
How to achieve Runtime polymorphism |
Texte |
The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance. C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function. Consider the following example where a base class has been derived by other two classes: abstract class Figure { int dim1, dim2; Figure(int x, int y) { dim1 = x; dim2 = y; } abstract void area(); } class Triangle extends Figure { Triangle(int x, int y) {
|
Envoyé |
Oui |
Condensat |
abstract achieve appeared are area base been c++ call cause class classes classes: coding consider depending derived different dim1 dim2 dim2; example executed extends figure first following forms function has having hierarchy how inheritance int invokes many means member object occurs other polymorphism post related runtime security triangle two type typically void when where will word |
Tags |
|
Stories |
|
Notes |
|
Move |
|