Tell me what is the basic difference between a virtual base class and an abstract base class.
Printable View
Tell me what is the basic difference between a virtual base class and an abstract base class.
Never heard of it :(
A virtual class is a class with a virtual function. An abstract class is a class that has a pure virtual function. One cannot create abstract classes (only subclasses of abstract classes). However, non-abstract virtual classes can be instantiated. Confusing enough? :).
Code:class virtualClass {
public:
virtual void someVirtualFunc();
};
class abstractClass {
public:
virtual void pureVirtualFunc()=0;
};
Yea, that IS confusing...
>> Yea, that IS confusing...
Well, not really. Its actually quite logical.
eg.In the above class we have an abstract class called teacher. It has its contructor and a pure virtual function called 'TeachClass()'. Obviously this function would be differernt according to each different type of teacher (eg. Science teacher). The science teacher would be a subclass of Teacher and it would overload the pure virtual functions with their own version of them like the following.Code:class Teacher
{
public:
virtual void Teacher();
char fname[256];
char sname[256];
virtual void TeachClass();
}
Its not that confusing after all :DCode:class ScienceTeacher : public Teacher
{
void TeachClass()
{
// do special science stuff
}
}
You're wrong... it's SO Confusing!! :(
Don't fret... it'll just take some time to 'click' with you I guess... It makes sense though! :p
In face_master's example, TeachClass() is virtual function member of Teacher, which means that when you derive a class from Teacher (excuse the terminology :)) TeachClass() can be redefined to fit that class if it chooses not to use the default from Teacher if it's defined
I just read what I posted and I think I probably confused you more :(
Look at some tutorials...
One other thing... you cannot create instances of abstract classes; remember this.Cannot be doneCode:abstractClass ac;
>Confusing enough? :).
Only to those who do not already understand it. This seems to be the case with almost everything in C++. ;)
-Prelude