#include <iostream>
using namespace std;
class Coordinate
{
public:
Coordinate(int x,int y);
~Coordinate();
int getX();
int getY();
private:
int m_iX;
int m_iY;
};
class Line
{
public:
Line(int x1,int y1,int x2,int y2);
~Line();
void print();
private:
Coordinate *m_pCoorA;
Coordinate *m_pCoorB;
};
//函数实现部分
Coordinate::Coordinate(int x,int y):m_iX(x),m_iY(y)
{}
Coordinate::~Coordinate(){}
int Coordinate::getX()
{
return m_iX;
}
int Coordinate::getY()
{
return m_iY;
}
Line::Line(int x1,int y1,int x2,int y2)
{
m_pCoorA = new Coordinate(x1,y1);
m_pCoorB = new Coordinate(x2,y2);
}
Line::~Line()
{
delete m_pCoorA;
delete m_pCoorB;
}
void Line::print()
{
cout<<"("<<m_pCoorA->getX()<<","<<m_pCoorA->getY()<<")"<<endl;
cout<<"("<<m_pCoorB->getX()<<","<<m_pCoorB->getY()<<")"<<endl;
}
int main()
{
Line *p=new Line(1,2,3,4);
p->print();
delete p;
return 0;
}
using namespace std;
class Coordinate
{
public:
Coordinate(int x,int y);
~Coordinate();
int getX();
int getY();
private:
int m_iX;
int m_iY;
};
class Line
{
public:
Line(int x1,int y1,int x2,int y2);
~Line();
void print();
private:
Coordinate *m_pCoorA;
Coordinate *m_pCoorB;
};
//函数实现部分
Coordinate::Coordinate(int x,int y):m_iX(x),m_iY(y)
{}
Coordinate::~Coordinate(){}
int Coordinate::getX()
{
return m_iX;
}
int Coordinate::getY()
{
return m_iY;
}
Line::Line(int x1,int y1,int x2,int y2)
{
m_pCoorA = new Coordinate(x1,y1);
m_pCoorB = new Coordinate(x2,y2);
}
Line::~Line()
{
delete m_pCoorA;
delete m_pCoorB;
}
void Line::print()
{
cout<<"("<<m_pCoorA->getX()<<","<<m_pCoorA->getY()<<")"<<endl;
cout<<"("<<m_pCoorB->getX()<<","<<m_pCoorB->getY()<<")"<<endl;
}
int main()
{
Line *p=new Line(1,2,3,4);
p->print();
delete p;
return 0;
}