- 论坛徽章:
- 0
|
非常感谢大家,修改了一下,能达到我目的了
#include <vector>
using namespace std;
struct Point
{
double x;
double y;
Point(){x=121.12345;y=31.54321;}
Point& operator=(const Point& rhs)
{
this->x = rhs.x;
this->y = rhs.y;
return *this;
}
};
class Line
{
public:
Line(){pt_num=0;pt=NULL;}
Line(int num)
{
length = 0;
pt_num = num;
pt = new Point[num];
}
Line(const Line& rhs)
{
if (this == &rhs)
{
return;
}
length = rhs.length;
pt_num = rhs.pt_num;
pt = new Point[rhs.pt_num];
for (int i = 0; i < rhs.pt_num; i++)
{
pt[i] = rhs.pt[i];
}
}
~Line()
{
if (pt)
{
delete [] pt;
pt = NULL;
}
}
Line& operator = (const Line& rhs)
{
if (this == &rhs)
{
return *this;
}
length = rhs.length;
pt_num = rhs.pt_num;
pt = new Point[rhs.pt_num];
for (int i = 0; i < rhs.pt_num; i++)
{
pt[i] = rhs.pt[i];
}
return *this;
}
public:
int length;
int pt_num;
Point *pt;
};
typedef vector<Line> Polyline;
int _tmain(int argc, _TCHAR* argv[])
{
{
Polyline polyline;
{
Line line(2);
// line.pt[0].x = 11;
// line.pt[0].y = 22;
// line.pt[1].x = 33;
// line.pt[1].y = 44;
polyline.push_back(line);
}
}
return 0;
}
|
|