TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Virtual Function in OOPS
Barkha Gupta
Jan 22
2016
Code
1.3
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
* /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