1. Home
  2. Computing & Technology
  3. C / C++ / C#

Learn about C++ Classes and Objects

By , About.com Guide

6 of 9

Learn about Inheritance

The class Circle is derived from the Point class. This is done in this line:
class Circle : Point {
Because it is derived from a base class (Point), Circle inherits all the class members.
Point(int atx,int aty ) ; // Constructor
inline virtual ~Point() ; // Destructor
virtual void Draw() ;
Circle(int atx,int aty,int theRadius) ;
inline virtual ~Circle() ;
virtual void Draw() ;
Think of the Circle class as the Point class with an extra member (radius). It inherits the base class Member functions and private variables x and y.

It cannot assign or use these except implicitly because they are private, so it has to do it through the Circle constructor's Initialiazer list. This is something you should accept for now, I'll come back to initializer lists in a future tutorial.

In the Circle Constructor, before theRadius is assigned to radius, the Point part of Circle is constructed through a call to Point's constructor in the initializer list. This list is everything between the : and the { below.

Circle::Circle(int atx,int aty,int theRadius) : Point(atx,aty)
Incidentally, constructor type initialization can be used for all built-in types.
int a1(10) ;
int a2=10 ;
Both do the same.

On the next page : What is Polymorphism?

Explore C / C++ / C#
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. C++
  5. Learn C++ Programming
  6. Learn about Inheritance

©2009 About.com, a part of The New York Times Company.

All rights reserved.