hocker@enuxha.eas.asu.edu (Charles C. Hocker) (12/10/90)
Hello,
I am currently working a graphics program and I am have some
problems with abstract base types. What I would like to do is
create some routines for independent output devices (ie. printer,
plotter, screen, etc).
The following is a code fragment of my program:
class Device { // used as an interface for the physical devices
public:
iMinMax device; // physical device limits
Device (void); // constructor for device
virtual void line (iPoint&, iPoint&); // would like this to
// be specific for each
// type of device.
};
class Screen : public Device {
public:
iMinMax screen; // screens physical limits
Screen (void) {device = screen;} // set the device limits
void line (iPoint&, iPoint&); // this is the line routine
// I want device to use
};
class Viewport : virtual public Device {
public:
fMinMax viewport;
Viewport (void);
void line (fPoint&, fPoint&); // NOTE: different line
// routine.
};
//
// Device
//
Device::Device (void)
{
}
//
// Screen
//
// THIS IS THE ROUTINE I WANT DEVICE TO CALL WHEN IT DRAWS A LINE
void Screen::line (iPoint p1, iPoint p2)
{
line (p1, p2); // The actual line drawing routine
// ...
}
//
// Viewport
//
Viewport::Viewport (void)
{
}
void Viewport::line (fPoint& p1, fPoint& p2)
{
iPoint pi1, pi2;
pi1 = Viewport_to_Device (p1);
pi2 = Viewport_to_Device (p2);
Device::line (pi1, pi2);// I want to actually call
// Screen::line (pi1, pi2);
}
When I specify the device routine to be pure, the other routines in Viewport
generate an error. If I do not specify the Device routine to be pure,
the compiler generates an error about Device::line (...) not being defined.
BTW, I am using Turbo C++ 1.00 if it makes a difference.
Charles C. Hocker
hocker@enuxha.eas.asu.edu