4.3 AN INTRODUCTION TO OBJECT ORIENTATION

4.3.1 From structures to objects

Objects can be considered as development over structures. Consider the example of a date. A date forms part and parcel of many programs. It can be your birthday! It may be a maturity date of your fixed deposit. It may be the date when this text file is created. Programmers used to define a structure like:

Struct Date

   { int day;

     int month;

     int year;

   } ;

and later on declare variables of type Date. A pictorial view of Structure Date can be seen in Figure 4.1. If a programmer used this structure in one program, it was not giving him any help or convenience in writing another program. The date could get modified inadvertently and produce errors which are very ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.