Abstract Classes

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2008
Posts: 3
Reputation: Simran1 is an unknown quantity at this point 
Solved Threads: 0
Simran1 Simran1 is offline Offline
Newbie Poster

Abstract Classes

 
0
  #1
Dec 31st, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,048
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 309
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: Abstract Classes

 
0
  #2
Dec 31st, 2008
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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 638
Reputation: Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough 
Solved Threads: 103
Murtan Murtan is offline Offline
Practically a Master Poster

Re: Abstract Classes

 
0
  #3
Dec 31st, 2008
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;
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 31
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: Abstract Classes

 
0
  #4
Dec 31st, 2008
Originally Posted by Murtan View Post
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).
Originally Posted by Murtan View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 18
Reputation: da penguin is an unknown quantity at this point 
Solved Threads: 5
da penguin's Avatar
da penguin da penguin is offline Offline
Newbie Poster

Re: Abstract Classes

 
0
  #5
Dec 31st, 2008
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.
No, ma'am, we are musicians.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 462
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 71
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: Abstract Classes

 
0
  #6
Dec 31st, 2008
my 2 cents:
-> you can declare pointers and references to the abstract class to use polymorphic behaviour
thanks
-chandra
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 494 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC