Dominating Member Functions
If you want to dominate a Member function you would have to do the following:
 | |  | | |
#include <iostream.h>
#include "tq.h"
int main()
{
Human Human1;
Human1.Speak();
Human1.getAge();
Male Cory;
Cory.Speak();
cout <<"Kristy is overiding a member function of human....n";
Female Kristy;
Kristy.Human::Speak(); //Object then "." then baseclass then function
return 0;
} |
|  |
|
The resultant output would be "I'm a human, hello world!n". The reason for this is because you are overriding the member function of the base class Human. You dominate a class member by using this syntax:
 | |  | | |
Object.Class::Function(); |
|  |
|
As (you) can be seen the Object would be Kristy, the Class would be Human because you want to use the Human function not the Female Function and finally the Function(); would be Speak(); In most cases, you really would never have to do this, but its just one of the many things you can do with inheritance. We will show you an easier way to access the right member function by using virtual functions.
Please Rate this Code:
Comments for: Dominating Member Functions
There are NO user contributed comments for Dominating Member Functions.
|
 |
|
 |