Hello,
What is Abstract classes.Please tell me the definition and how to implement this also tell me please.
I'm waiting for your reply.

Thanks

If a base class is very general you can prevent instantiation of this class by making it abstract.

Example:
Polygon-->Quadrilateral-->Square
Here you make Polygon abstract. What would you want to do with a Polygon?It just holds some common properties for a triangle,rectangle etc. Even Quadrilateral could be abstract. The class you want to work with here is a Square. Square will never be abstract you must be able to instantianate a Square into an object to work with.

Abstract classes are not instantiateable (you can't make one) for example, if Polygon is abstract, the compiler will not let you call: new Polygon(); A class is normally made abstract by defining one (or more) methods as 'pure virtual'. A pure virtual method is one that is declared (return type, arguments, etc.) but not defined (no function body).

Something like virtual int draw() = 0;

A pure virtual method is one that is declared (return type, arguments, etc.) but not defined (no function body).

That's not true. A pure virtual function can be defined (i.e. it can have a function body).

Something like virtual int draw() = 0;

In C++, the "=0" in the declaration is what makes the function pure virtual. In C++, a class with one or more pure virtual function is abstract, and cannot be instantiated. The purpose is that the base class provides a defined interface, and derived classes are forced to override and supply their own versions of the pure virtual functions. In this way, derived classes implement (or extend) the interface that is specified by the abstract base class.

Guess it would be good to mention that an abstract class is mostly an interface, a common interface for all derevied ones. For example you can make an abstract class with only one pure virtual overloaded operator= and derive from it all "assignable" classes.

my 2 cents:
-> you can declare pointers and references to the abstract class to use polymorphic behaviour

This article has been dead for over six months. Start a new discussion instead.