what is virtual function in c++
Answers were Sorted based on User's Feedback
Answer / achal
the concept of vitual function comes when inheritance is at
work. If the overriden function is not made virtual in base
class , then pointer of derived class will call the funtion
in base class(instead it should have called the one from
derived class.)
this is why we make the function in base as virtual.
| Is This Answer Correct ? | 37 Yes | 6 No |
Answer / sree
virtual function comes into picture while inheriting the
base class functions to the derived class functions.
ifthe virtual isnot used then the pointer of derived class
points to the baseclass function
| Is This Answer Correct ? | 28 Yes | 1 No |
Answer / indu
IT'S OVERRIDING A BASE CLASS DEFINITION AT RUN TIME.MEMBER
FUNCTION IN BASE CLASS AND DERIVED CLASS IS SAME. NORMALLY
IT INVOKE THE BASE CLASS DEFINITION IF BOTH FUNCTION NAME
IS SAME.BUT WE NEED TO ACCESS THE DERIVED CLASS DEFINITION
WE GO FOR VIRTUAL FUNCTION
| Is This Answer Correct ? | 20 Yes | 3 No |
Answer / b.balaganesan
Virtual, as the name implies, is something that exists in
effect but not in reality. The concept of virtual function
is the same as a function, but it does not really exist
although it appears in needed places in a program. The
object-oriented programming language C++ implements the
concept of virtual function as a simple member function,
like all member functions of the class.
Need for Virtual Function:
The vital reason for having a virtual function is to
implement a different functionality in the derived class.
For example: a Make function in a class Vehicle may have to
make a Vehicle with red color. A class called FourWheeler,
derived or inherited from Vehicle, may have to use a blue
background and 4 tires as wheels. For this scenario, the
Make function for FourWheeler should now have a different
functionality from the one at the class called Vehicle.
This concept is called Virtual Function.
| Is This Answer Correct ? | 10 Yes | 3 No |
Answer / hemin_sdek@yahoo.com
IT'S OVERRIDING A BASE CLASS DEFINITION AT RUN TIME.MEMBER
FUNCTION IN BASE CLASS AND DERIVED CLASS IS SAME. NORMALLY
IT INVOKE THE BASE CLASS DEFINITION IF BOTH FUNCTION NAME
IS SAME.BUT WE NEED TO ACCESS THE DERIVED CLASS DEFINITION
WE GO FOR VIRTUAL FUNCTION
| Is This Answer Correct ? | 6 Yes | 2 No |
Answer / guest
virtual funtion in cpp is define as globle acess in the
variable.
| Is This Answer Correct ? | 14 Yes | 41 No |
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.
Why it is called runtime polymorphism?
how much classes are used in c++
what is single inheritance?
What is multilevel inheritance explain with example?
What does and I oop mean in text?
i=20;k=0; for(j=1;k-i;k+=j<10?4:3) { cout<<k; } //please comment on the output
#include <string.h> #include <stdio.h> #include <stdlib.h> #include<conio.h> void insert(char *items, int count); int main(void) { char s[255]; printf("Enter a string:"); gets(s); insert(s, strlen(s)); printf("The sorted string is: %s.\n", s); getch(); return 0; } void insert(char *items, int count) { register int a, b; char t; for(a=1; a < count; ++a) { t = items[a]; for(b=a-1; (b >= 0) && (t < items[b]); b--) items[b+1] = items[b]; items[b+1] = t; } } design an algorithm for Insertion Sort
The IT giant Tirnop has recently crossed a head count of 150000 and earnings of $7 billion. As one of the forerunners in the technology front, Tirnop continues to lead the way in products and services in India. At Tirnop, all programmers are equal in every respect. They receive identical salaries and also write code at the same rate. Suppose 14 such programmers take 14 minutes to write 14 lines of code in total. How long will in take 5 programmers to write 5 lines of code in total ?
write a c++ program to find maximum of two numbers using inline functions.
How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?
What is the difference between pass by value,pass by pointer,pass by reference in the catch block in the exception handling in c++