| | |
Abstract Classes
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2008
Posts: 3
Reputation:
Solved Threads: 0
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
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.
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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: May 2008
Posts: 638
Reputation:
Solved Threads: 103
Abstract classes are not instantiateable (you can't make one) for example, if Polygon is abstract, the compiler will not let you call:
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
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; •
•
Join Date: Aug 2008
Posts: 206
Reputation:
Solved Threads: 31
•
•
•
•
A pure virtual method is one that is declared (return type, arguments, etc.) but not defined (no function body).
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.
![]() |
Similar Threads
- php: abstract classes (whats the point behind them) (PHP)
- abstract classes (Java)
- im on interfaces, abstract classes (Java)
- Abstract Classes VS Interface (Java)
- Abstract classes (Java)
- Query about static nested classes (Java)
- abstract class (Java)
Other Threads in the C++ Forum
- Previous Thread: Reading Data from text file
- Next Thread: one event handler function for a number of messages - MFC
Views: 494 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






