Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Virtual Function in OOPS
WhatsApp
Barkha Gupta
Jan 22
2016
1.4
k
0
0
* /program to illustrate
virtual
function./ *
#include < iostream > using namespace std;
class
base
{
public
:
void
display()
{
cout <<
"\ndisplay base"
;
}
virtual
void
show()
{
cout <<
"\nshow derived"
;
}
};
class
derived:
public
base
{
public
:
void
display()
{
cout <<
"\nderived display"
;
}
void
show()
{
cout <<
"\nshow derived"
;
}
};
int
main()
{
base
b;
derived d;
base
* bptr;
cout <<
"\nbptr points to base"
;
bptr = & b;
bptr - > display();
bptr - > show();
cout <<
"\nbptr points to derived"
;
bptr = & d;
bptr - > display();
bptr - > show();
return
0;
}
OOPs
Virtual Function