What is Pure Virtual Function? Why and when it is used ?
Answer Posted / talha bilal
Pure Virtual Function
class Base //Abstract base class
{
public:
virtual void show() = 0; //Pure Virtual Function
};
class Derived:public Base
{
public:
void show()
{
cout << "Implementation of Virtual Function in Derived class";
}
};
int main()
{
Base obj; //Compile Time Error
Base *b;
Derived d;
b = &d;
b->show();
}
Virtual Function
class Base
{
public:
virtual void show()
{
cout << "Base class";
}
};
class Derived:public Base
{
private:
void show()
{
cout << "Derived Class";
}
};
int main()
{
Base *b; //Base class pointer
Derived d; //Derived class object
b = &d;
b->show(); //Late Binding Occurs
}
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
Can you help me with this one? Make a program that when a user inputed a Product Name, it will display its price, and when the user inputed the quantity of the inputed product, it will show its total price. The output must be like this: Product Name: Price: Quantity: Total Price: ..this is the list of products to be inputed: Cellphone - 1500 Washing Machine - 5200 Television - 6000 Refrigirator - 8000 Oven - 2000 Computer - 11000 thanks..:D
Write a program using GUI concept for the scheduling algorithms in Operating system like SJF,FCFS etc..
How can a struct in c++ differs from a struct in c?
What are its advantages and disadvantages of multiple inheritances (virtual inheritance)?
In c++, what is the difference between method overloading and method overriding?
which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?
Are c and c++ similar?
Is c++ primer good for beginners?
Why do we use classes in c++?
What are c++ manipulators?
What do you mean by ‘void’ return type?
What is the function of I/O library in C++ ?
What is the use of class in c++?
What is the protected keyword used for?
Is java made in c++?