Re: Help a beginner
Steven Green <steven.green30 @verizon.net> wrote in message news:<pan.2003. 12.20.00.41.50. 909223@verizon. net>...[color=blue]
> class Line
> {
> public:
> Point* start_point;
> Point* end_point;
> public:
> Line(Point*, Point*);
> };
>
> Line::Line(Poin t* initp1, Point* initp2)
> {
> start_point=ini tp1;
> end_point=initp 2;
> return;
> }
>
> main()
> {
> Point p1(10,20);
> Point p2(20,40);
> Line l1(&p1,&p2);
> }
>
> I removed the line is-a point relationship which makes little sence.
> Additionally, I used pointers to avoid the calling of the default
> constructor.
>
> --Steve[/color]
Now, though, Line doesn't own its Points anymore ... in this example,
if you pass l1 as a return value or do anything that extends its
lifetime beyond p1 and p2, you'll have problems. Unless Points are
really expensive to create and/or copy, this may not be the best way
to do it.
My two cents at least,
Michael
Steven Green <steven.green30 @verizon.net> wrote in message news:<pan.2003. 12.20.00.41.50. 909223@verizon. net>...[color=blue]
> class Line
> {
> public:
> Point* start_point;
> Point* end_point;
> public:
> Line(Point*, Point*);
> };
>
> Line::Line(Poin t* initp1, Point* initp2)
> {
> start_point=ini tp1;
> end_point=initp 2;
> return;
> }
>
> main()
> {
> Point p1(10,20);
> Point p2(20,40);
> Line l1(&p1,&p2);
> }
>
> I removed the line is-a point relationship which makes little sence.
> Additionally, I used pointers to avoid the calling of the default
> constructor.
>
> --Steve[/color]
Now, though, Line doesn't own its Points anymore ... in this example,
if you pass l1 as a return value or do anything that extends its
lifetime beyond p1 and p2, you'll have problems. Unless Points are
really expensive to create and/or copy, this may not be the best way
to do it.
My two cents at least,
Michael
Comment