Click here to Skip to main content
14,937,556 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
When I use abstract classes? How do I make a concrete class abstract?
Posted

Abstract classes are mainly used for specify interfaces (interface is a basic OOP concept, make sure to grasp it).
You transform a concrete class into an abstract one simply adding to it a pure virtual method (or changing an existing method to pure virtual), e.g.
C++
// 'Concrete' Foo
class Foo
{
  //... Foo definition
};


// 'Abstract' Foo
class Foo
{
  //... Foo definition
  virtual do_something()=0;
};
   
An abstract class in C++ contains at least one pure virtual function which is a function defined as:
C++
virtual void foo() = 0;
.
The important part here is the "= 0" statement.

If you inherit from an abstract class you'll have to provide function definitions for every inherited pure virtual function. Otherwise it is not possible to create an instance of the derived class. Hence in terms of C++ it is not possible to instantiate abstract classes.
   
v2
Answer to your first question:-

19,000,000 results for when to use an abstract class

Now, why do you require to make a concrete class abstract? As:-

http://www.brpreiss.com/books/opus4/html/page611.html

I hope this will clear out your confusion.

Thanks
   
Comments
Adam_adam 21-Aug-12 8:10am
   
thanks,I am a beginner in programming
Varun Sareen 21-Aug-12 10:34am
   
your welcome dear
abstract class is base class for define other classes ex: team is developing graphics application and team is designing Line and Circle class but it is necessary both class have method with the conman name in this case team lead define an abstract class name Graphics and ask developer to derive class from the Graphics.

Abstract class dose not have method body it provide empty implementation of method but after deriving this class to other class developer has to override methods define in the base class in this way developer will develop the derived classes with the same method name as define in abstract class

concrete class is class which is derive from abstract class.
I don't know how to define concrete class abstract class
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900