标签:private namespace 来源 htm life poi name cout www.
#include <iostream> #include <string> #include <sstream> using namespace std; class Object { protected: string mName; string mInfo; public: Object() { mName="Object"; mInfo=""; } string name() { return mName; } string info() { return mInfo; } }; class Point : public Object { protected: int x; //坐标 int y; public: Point(int x=0,int y=0) { ostringstream s; this->x=x; this->y=y; s<<"P("<<x<<","<<y<<")"; //坐标信息 mName="Point"; mInfo=s.str(); } }; class Line : public Object { private: Point mP1; Point mP2; public: Line(Point p1,Point p2) { ostringstream s; mP1 =p1; mP2 =p2; s<<"Line from " <<p1.info() <<" to "<<p2.info(); //线的信息 mName ="Line"; mInfo =s.str(); } }; int main() { Point p1(2,3); Point p2(6,3); Line L(p1,p2);
cout<<p1.name()<<":"<<endl; cout<<p1.info()<<endl; cout<<L.name()<<":"<<endl; cout<<L.info()<<endl; return 0; }
文章来源:https://www.cnblogs.com/lifexy/p/8698104.html
标签:private namespace 来源 htm life poi name cout www.
原文地址:https://www.cnblogs.com/xiongjim/p/9673952.html