hi
I have a base class called shape and 3 drived classes: line, rect, circle.
in addition I have drawing class that contins array of shape*.
I successfully overloaded opertor << for line, rect and circle and now i try to overload << for drawing class. I tried the following:
and I got this error:Code:ostream& operator << (ostream& os, const Drawing& drw) { for(int i=0; i<drw.size_;i++) if (!(drw.drawing_[i].is_empty())) os << drw.drawing_[i]<<endl; return os<<endl; }
no match for operator << in 'os<<*shape'
so I tried casting:
and then I got:Code:... switch ( int(drw.drawing_[i].type()) ){ case 1: os << dynamic_cast<Line*>(&drw.drawing_[i]) <<endl; break; case 2: os << dynamic_cast<Rect*>(&drw.drawing_[i]) <<endl; break; case 3: os << dynamic_cast<Circle*>(&drw.drawing_[i]) <<endl; break; } ...
error: cannot dynamic cast shape* to Line* (source is not polymorphic)
any ideas??



LinkBack URL
About LinkBacks



