I have ancestor abstact class called Figure
class Figure {
public:
string style, color, name;
virtual void printInfo() = 0;
/*
different methods here
*/
virtual Figure operator * (int prod) = 0;
};
And I have Line class (and few others) that inherites Figure.
class Line : public Figure {
/* .... */
Line operator*(int prod);
};
Line Line::operator *(int prod) {
Line temp = *this ;
Point p = getPoint2();
p.setXYZ(p.getX() * prod, p.getY() * prod, p.getZ() * prod);
temp.setPoint2(p);
return temp;
}
The point is that I want to have such virtual operator, but if I write code as above I get dozen of mistakes.
What have I done wrong?
Figureis an abstract class, so you can’t return it by value. It is abstract because it has pure virtual methods. Abstract classes cannot be instantiated.