Hi,
Is there any concept called 'Virtual Class' present in C++ ?
Thanks
Kiran
Printable View
Hi,
Is there any concept called 'Virtual Class' present in C++ ?
Thanks
Kiran
Not by that name. What does it mean?
Yes, by with different name.
What is it ?
Is it mean by inheriting a base class as Virtual one ?
If Virtual class is something like an abstract base class then there´s an equivalent in C++. Unlike as in java you don´t have to mark the abstract base class, all you have to do is to declare a pure virtual function and the class is automatically abstract.
Code:/*no keyword needed here*/ class AbstractBaseClass
{
public:
AbstractBaseClass();
virtual ~AbstractBaseClass();
// pure virtual function declaration makes this class virtual/abstract
virtual func() = 0;
};
class ConcreteClass : public AbstractBaseClass
{
public:
ConcreateClass();
// implementation of inherited pure virtual function
void func();
};
I guess you could call a class virtual if it contains virtual functions. If all functions are pure virtual you could call the class abstract or an interface.Quote:
Originally Posted by rsodimbakam
Then there's something called virtual inheritance. It's a way do avoid problems with multiple copies of the same class in a multiple inheritance situation. A class can be declared to be virtually inherited by the inheriting class.