hi i just done some coding about base class shape and derived class twod and threed..
can anyone show me my wrong?
Code:class Shape { public: Shape(){}; void print(); } class TwoD:public Shape { public: TwoD( double a =0.0,double b = 0.0): length(a),width(b){ setdata(a,b); } virtual double area() {return 0} void setdata(double a,double b){ length = a; width = b; } void print(){ cout<<length<<','<<width<<endl; } protected: double length,width; } class Threed:public TwoD{ friend ostream &operator<<(ostream &stream,Threed o); friend Threed operator*(int &Number,Threed &o); public: Threed operator++(); Threed operator*(int &Number); Threed(double a,double b,double c):TwoD(a,b),height(c){ setdata(a,b,c);} void print() { cout<<length<<','<<width<<','<<height<<endl; } void setdata( double a, double b,double c) { length = a; width = b; height = c; } protected: double height; } Threed Threed::operator++(){ length++;width++;height++;return *this; } Threed operator*(int &number,Threed &o) { Threed a; a.length= number*o.length; a.width= number*o.width; a.height= number*o.height; return a; ostream &operator<<(ostream &stream, Threed o) { stream << o.length << " "; stream << "(" << o.width << ") "; stream << o.height << "-"; return stream; // must return stream } int main() { ThreeD a(1,2,3),b(1,2),c(1); ++a; c = a*2;//use member function overloading c= 2*a;//use global function overloading return 0; }



LinkBack URL
About LinkBacks


