O'Reilly logo

Inside the C++ Object Model by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 1. Object Lessons

In C, a data abstraction and the operations that perform on it are declared separately—that is, there is no language-supported relationship between data and functions. We speak of this method of programming as procedural, driven by a set of algorithms divided into task-oriented functions operating on shared, external data. For example, if we declare a struct Point3d, such as the following:

typedef struct point3d 
{ 
   float x; 
   float y; 
   float z; 
} Point3d; 

the operation to print a particular Point3d might be defined either as a function

void 
Point3d_print( const Point3d *pd ) 
{ 
   printf(”( %g, %g, %g )”, pd->x, pd->y, pd->z ); 
} 

or, for efficiency, as a preprocessor macro:

 #define Point3d_print( pd ) \ printf(”( %g, %g, %g )”, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required