943,775 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 714
  • C++ RSS
Dec 31st, 2008
0

Abstract Classes

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Simran1 is offline Offline
3 posts
since Dec 2008
Dec 31st, 2008
0

Re: Abstract Classes

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.
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is online now Online
3,738 posts
since Oct 2008
Dec 31st, 2008
0

Re: Abstract Classes

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;
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008
Dec 31st, 2008
0

Re: Abstract Classes

Click to Expand / Collapse  Quote originally posted by Murtan ...
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).
Click to Expand / Collapse  Quote originally posted by Murtan ...
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.
Reputation Points: 193
Solved Threads: 32
Posting Whiz in Training
grumpier is offline Offline
206 posts
since Aug 2008
Dec 31st, 2008
0

Re: Abstract Classes

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.
Reputation Points: 36
Solved Threads: 5
Newbie Poster
da penguin is offline Offline
18 posts
since Dec 2008
Dec 31st, 2008
0

Re: Abstract Classes

my 2 cents:
-> you can declare pointers and references to the abstract class to use polymorphic behaviour
Featured Poster
Reputation Points: 431
Solved Threads: 116
Practically a Master Poster
Agni is offline Offline
654 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Reading Data from text file
Next Thread in C++ Forum Timeline: one event handler function for a number of messages - MFC





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC