c++(cplusplus)-Abstract-base-class

ABSTRACT BASE CLASS

An abstract class contains at least one pure virtual function. In the class declaration, if the declaration of a virtual member function is done by appending 0 zero to the function declaration then the function is pure virtual function.

class Base {

public:

virtual void func() = 0;

};

An abstract class cannot be used as a parameter type, a function return type, or the explicit conversion type.The most importtant thing is that one cannot declare the object of an bastract class.However, declaring pointers and references to an abstract class is possible.

As virtual member functions can be inherited, a class derived from an abstract base class can also be abstract unless overriding of each pure virtual function in the derived class is done.

For example:

class Base {

public:

virtual void func1() = 0;

};

class Derived : public Base {

void func2();

};

int main() {

Derived obj;

}

The compiler does not allow the declaration of object obj because Derived is an abstract class and it inherited the pure virtual function func1() from Base class. The declaration of object obj will be allowed by compiler if function is defined as Derived :: func2().

css.php