class Pixel
{
public:
int x, y; // coordinate
};
For now, let us not worry about the public: part. This definition
means that all objects of Pixel type has two data members
(also known as fields): x and y.
Using this definition, we can proceed to create objects of this
Pixel class, as follows:
Pixel dotA, dotB;
We can access individual data member using the dot notation. For example, we can use the following code to initialize a pixel to the origin of a screen:
dotA.x = dotA.y = 0;
We can also write a subroutine to reset a pixel to the origin:
void pixelReset(Pixel &p)
{
p.x = p.y = 0;
}
So far, everything that we have done can be done with
a struct definition. We can add additional subroutines that
deal with pixels. For example:
pixelDraw: a subroutine to draw a pixel
pixelErase: a subroutine to erase a pixel