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
What is & in c++ function?
What is an inline function in c++?
Should the member functions which are made public in the base class be hidden?
What character terminates all character array strings a) b) . c) END
Difference between inline functions and macros?
Is c++ a float?
What are the steps in the development cycle?
Why iomanip is used in c++?
How one would use switch in a program?
What does obj stand for?
Difference between strdup and strcpy?
What are enumerations?
How much do coding jobs pay?
What is flush () in c++?
What is std :: flush?