May 1996
Intermediate to advanced
304 pages
5h 54m
English
If we have a Point3d pointer and object:
Point3d obj; Point3d *ptr = &obj;
the question is, what actually happens when we write
obj.normalize(); ptr->normalize();
where Point3d::normalize() is implemented as
Point3d
Point3d::normalize() const
{
register float mag = magnitude();
Point3d normal;
normal._x = _x/mag;
normal._y = _y/mag;
normal._z = _z/mag;
return normal;
} and Point3d::magnitude() is implemented as
float
Point3d::magnitude() const
{
return sqrt(
_x * _x + _y * _y + _z * _z
);
} The answer is, we don’t yet know. C++ supports three flavors of member functions: static, nonstatic, and virtual. Each is invoked differently; those differences are the topic of the next section. (A short quiz: Although ...
Read now
Unlock full access