UrbanPro

Learn C++ Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How do I achieve polymorphism in C++ using virtual functions?

Asked by Last Modified  

Follow 1
Answer

Please enter your answer

Experienced Computer trainer having worked in IT sector for 20 years.

The main use of virtual function is to achieve Runtime Polymorphism. Runtime polymorphism can be achieved only through a pointer (or reference) of base class type. Also, a base class pointer can point to the objects of base class as well as to the objects of derived class.
Comments

Step 1: Define the base class containing a virtual method. class Arithmetic { public: virtual void calc(); }; Step 2: Create the subclass. Also write the implementation of the virtual method. class Addition { public: void calc() { // logic of addition ...
read more

Step 1: Define the base class containing a virtual method.

class Arithmetic

{

public: 

         virtual void calc();

};

Step 2: Create the subclass. Also write the implementation of the virtual method.

class Addition

{

public: 

         void calc()

         {

               // logic of addition

          }

};

3) Creating pointer variable:,

void main()

{

    Arithmetic* obj1 = new Addition();

    obj1-> calc();

;

 

read less
Comments

Related Questions

What is a class?
Class is User defined data type, its contain data members and member function
Thinagaran
0 0
7
how to use dos.h
First include dos.h header file then use their function. Before use function, you must have knowledge of dos functions and their charactistics
Aman
What is C++
A high-level programming language developed by Bjarne Stroustrup at Bell Labs. C++ adds object-oriented features to its predecessor, C. C++ is one of the most popular programming language for graphical...
Shoaib
please tell me the best book for c programming language
LET US C by Yashwant Kanetkar. This book is very useful to improve the practical Knowledge. For Theory - Programming in C by Balagurusamy
Sunil
i am a student of 11th class and i want to make my future in C++ is this possible i am take arts inn 11th class
Definitely.. but you should be flexible moving to java/ other languages as well.. requirement/ demand keep changing in software. i can do the needful.. with 18+ yrs exp in working on live projects...
Rajneesh

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Polymorphism and Virtual Functions
Polymorphism and Virtual Functions Compile Time Polymorphism or Early Binding or Static Binding An object is bound to its function call at compile time. Implemented using overloaded functions and...

Magic in C=> OFFSET OF MACRO in C [offsetof(TYPE, MEMBER)]
Here I am going to discuss an exciting macro in C. It will give you offset of a member within a structure. NULL or 0 address is typecasted to TYPE first. It won't result in segmentation fault as we are...

C++ Program Sample Application
//Standard Library Functions(Headers Files Used in C++) #include<iostream.h> #include<conio.h> //Main function int main() { //function for clearing the screen clrscr(); //function for...

Swapping Two Numbers
Q. Swap two numbers using the following function. Complete the function. You won't be allowed to use a temporary variable to swap the two numbers. void swap ( ... ) { /* Swap code goes here */ } ...

Turbo C++ Keyboard Shortcuts
S.No. Shortcuts keys Action 1. F1 For Help 2. F2 Save 3. F3 Open 4. F4 Go to cursor 5. F5 Zoom 6. F6 Next 7. F7 Trace...

Recommended Articles

Introduction C++ is an excellent programming language and many of the applications are written in C++ language. It has generic, object-oriented & imperative programming features, and also provides facilities for low-level memory manipulation. Successor of C language, it is an OOP (object oriented programming) language...

Read full article >

Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today.  In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...

Read full article >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

Read full article >

Applications engineering is a hot trend in the current IT market.  An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...

Read full article >

Looking for C++ Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C++ Language Classes?

The best tutors for C++ Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C++ Language with the Best Tutors

The best Tutors for C++ Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more