Virtual functions
Thread Tags
Adobe Illustrator Adobe InDesign Adobe Photoshop Android Development Android Programming Android Studio Automation Testing C / C++ Programming Career Options College Lounge css designed Design layout digital marketing Digital Marketing / SEO Fireworks Graphic Design Graphic designing Graphics Design Graphics Designing HTML? Illustrator Internship Training logo Design logo designing mobile phones Photoshop QA react-native Scroll Website SEO Single Page Website Testing Typography UI UI/UX Development UI Design UI Designing UI development User Interface UX Design Viewport Web Designing web pages Website DesignRegister for free!
Registration at Smart Mentors is completely free and takes only a few seconds. By registering you’ll gain:
- Full Posting Privileges.
- Access to Private Messaging.
- Optional Email Notification.
- Ability to Fully Participate.
Register Now, or check out the Site Tour and find out everything Smart Mentors has to offer.
Tagged: C / C++ Programming
This thread contains 1 reply, has 2 voices, and was last updated by Nitesh User Do not delete 2 years, 2 months ago.
- Author Replies
- January 25, 2019 at 10:25 am #52558
A virtual function is a member function which is declared within the base class and is re-defined (Override) by the derived class. When you allude to a derived class object utilizing a pointer or a reference to the base class, you can call a virtual function for that object and execute the derived class’s version of the function.
Following things are important to compose a C++ program with runtime polymorphism (utilization of virtual capacities)
1) A base class and a derived class.
2) A function with the same name in base class and derived class.
3) A pointer or reference of base class type pointing or referring to an object of derived class.EXAMPLE: –
#include<iostream>
using namespace std;class Base {
public:
virtual void show() { cout<<” In Base \n”; }
};class Derived: public Base {
public:
void show() { cout<<“In Derived \n”; }
};int main(void) {
Base *xy = new Derived;
xy->show(); // RUN-TIME POLYMORPHISM
return 0;
}Output: In Derived
Regards,
Nitesh Bavishiya - AuthorPosts
You must be logged in to reply to this thread.Please login or register. Registration is 100% free.