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 )”, ...
Get Inside the C++ Object Model 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.