Hi,
I have a abstract base class polygon and want to write a pure virtual function to translate my polygon, however I cannot write 'virtual polygon translate(const coords trans)=0' as I will be trying to declare a parameter that has the type of an abstract base class.
What is a way around this?
// ASTRACT BASE CLASS FOR 2D POLYGONS
#ifndef POLYGON
#define POLYGON
usingnamespace std;
class polygon: public coords {
public:
// Virtual destructor
virtual ~polygon(){} //
// Pure virtual function to print info
virtualvoid info()=0;
// pure virtual function to translate polygon
//virtual polygon translate(const coords trans)=0;
}; // end of base class
#endif POLYGON
In my triangle class (which inherits the polygon class) the translation function (which works fine) is written as
1 2 3 4 5 6 7 8
// Function to translate the triangle by a set of coordinates
triangle translate(const coords trans){
triangle temp;
temp.sett1(t1+trans);
temp.sett2(t2+trans);
temp.sett3(t3+trans);
return temp;
}