#include?<iostream>using?namespace?std;class?Coordinate{ public: Coordinate(int?_x,int?_y); ~Coordinate(); int?getX(); int?getY(); private: int?x,y;?};class?Line{ public: Line(int?x1,int?y1,int?x2,int?y2); ~Line(); void?printLine(); private: Coordinate?*A; Coordinate?*B;};Coordinate::Coordinate(int?_x,int?_y){ cout?<<?"正在執(zhí)行?點(diǎn)類?構(gòu)造函數(shù)...??";? x?=?_x; y?=?_y; cout?<<?"("?<<?x?<<?","?<<?y?<<?")"?<<?endl;?}Coordinate::~Coordinate(){ cout?<<?"正在執(zhí)行點(diǎn)類析構(gòu)函數(shù)..."?<<?endl;?}int?Coordinate::getX(){ return?x;}int?Coordinate::getY(){ return?y;}Line::Line(int?x1,int?y1,int?x2,int?y2){ cout?<<?"正在執(zhí)行?線類?構(gòu)造函數(shù)..."?<<?endl; A?=?new?Coordinate?(x1,y1); B?=?new?Coordinate?(x2,y2);}Line::~Line(){ cout?<<?"正在執(zhí)行線類析構(gòu)函數(shù)..."?<<?endl; delete?A; A?=?NULL;? delete?B; B?=?NULL;}void?Line::printLine(){ cout?<<?"線類信息打印...?"; cout?<<?"("?<<?A->getX()?<<?","?<<?A->getY()?<<?")?"; cout?<<?"("?<<?B->getX()?<<?","?<<?B->getY()?<<?")"?<<?endl;}?int?main?(void){ Line?*line?=?new?Line?(1,2,3,4); line->printLine(); cout?<<?"line對(duì)象的大小為:?"?<<?sizeof(line)?<<?endl; cout?<<?"Line類型的大小為:?"?<<?sizeof(Line)?<<?endl; delete?line; line?=?NULL;}
2018-09-02
哪有showB,這樣直接粘貼過來是沒有格式的哦