Thread: C++ queries
View Single Post
Old 02-06-2001, 01:11 PM   #5
Paul Victorey
Member (12 bit)
 
Paul Victorey's Avatar
 
Join Date: Mar 1999
Location: MN or WI
Posts: 3,017
Glad we could be of assistance.

I hope you learn to truly use the power of virtual functions -- oh, BTW, a pure virtual function is declared like this:

class AbstractClass{
   virtual int PureVirtual() = 0;
};

All a pure virtual means is that there is an '= 0' after the definition. This means that you DO NOT provide any code for this function -- all child classes must implement this. Use pure virtual to force child classes to implement routines; use virtual if you want to provide a default function but want to allow children to override this.

Also, generally I prefer to make my interface classes (which are all abstract classes) very simple, only providing the functionality that any potential subclass could do.

For example, RGBImage, which has only pure virtual functions, has only a very few functions as well (I'm not listing the arguments here):

GetPixel();
SetPixel();
GetDimensions();
SetDimensions();

This is because, regardless of what kind of image it is, these functions apply. RGBImage is used by me for any image that does not use a palette but uses direct RGB color codes to store each pixel's color. The related PaletteImage class has a few more functions, but again, its functionality should be implementable for ANY image that uses a palette.

By creating common interfaces, the same code can be used to operate on a multitude of object types, even ones you haven't thought up yet.
__________________
Paul M. Victorey
------------------
I am not responsible for any problems that may arise as a result of following my advice. This includes, but is not limited to, computer failure, loss of data, nuclear war, famine, boils, no clean laundry, your daughter running off with a biker gang, or armageddon. Take my advice at your own risk.
Paul Victorey is offline   Reply With Quote