Source |
CodingSec |
Identifiant |
359465 |
Date de publication |
2017-04-26 14:00:38 (vue: 2017-04-26 14:00:38) |
Titre |
How to use virtual functions in Polymorphism (C++) |
Texte |
Virtual Functions We know that when a base class pointer refers to a derived class object, the extra features in derived class are not available. To access the extra features in the derived class, we make the functions in the base class as virtual. Syntax for creating a virtual function is as follows: 1 2 3 4 5 virtual return–type function–name(params–list) { //Body of function ... } A class which contains one or more virtual functions is known as a polymorphic class. Following program demonstrates accessing derived class features using virtual functions: 1 2 3 4 5 6
|
Envoyé |
Oui |
Condensat |
//body access accessing appeared are available base c++ class coding contains creating demonstrates derived extra features first following follows: function function–name functions functions: how know known make more not object one params–list pointer polymorphic polymorphism post program refers return–type security syntax use using virtual when which |
Tags |
|
Stories |
|
Notes |
|
Move |
|