lihongyu2467 发表于 2003-10-17 13:47:00

[求助]看看getClosestPointTo函数的使用

程序如下:
AcGeCurve2d *geCurve1,*geCurve2;
AcGePoint2d zjPt1,zjPt2;
geCurve1->getClosestPointTo(geCurve2,zjPt1,zjPt2);
编译时提示:
void __thiscall AcGeCurve2d::getClosestPointTo(const class AcGePoint2d &,class AcGePointOnCurve2d &,const class AcGeTol &) const' : cannot convert parameter 1 from 'class AcGeCurve2d *' to 'const class AcGePoint2d &
应该是*和&的问题吧,可是如何修改呢?谢谢了.

leeyeafu 发表于 2003-10-17 17:08:00

你所调用的getClosestPointTo()函数的原型是这样:
void getClosestPointTo(const AcGeCurve2d& curve2d,
       AcGePointOnCurve2d& pntOnThisCrv,
      AcGePointOnCurve2d& pntOnOtherCrv) const;
第一个参数需要一个AcGeCurve2d类对象的地址(或者说引用),在程序中geCurve1变量为指针,从而编译程序不能进行类型转换。你应该用*geCurve1来传递参数。
源码共享区内置顶文章“深入.......”就是回答这方面的,文章详细介绍了使用*和&进行函数参数传递时的方法,并且作了深入、详细的分析以回答为什么要那样做。建议你认真阅读那篇文章。

lihongyu2467 发表于 2003-10-18 00:21:00

真是痛苦,按照你的建议将geCurve2 改为*geCurve2,可仍然不行,编译提示:
void __thiscall AcGeCurve2d::getClosestPointTo(const class AcGePoint2d &,class AcGePointOnCurve2d &,const class AcGeTol &) const' : cannot convert parameter 1 from 'class AcGeCurve2d' to 'const class AcGePoint2d &
究竟改如何修改呢?麻烦你了,leeyeafu大哥.我着急用这个功能的.

mkhsj927 发表于 2003-10-20 09:03:00

我没具体分析,版主的方法不行的话,可能需要分析一下里面const的问题

leeyeafu 发表于 2003-10-20 09:31:00

我将你的程序复制到我写的一个ARX工程中编译,出现的编译错误是不能将参数2从AcGePoint2d转换为AcGePointOnCurve2d&,而不是你说的参数1类型错误。以下是我改写的程序,在VC6和VC++.NET中编译通过,因为没有其它代码(我也懒得写了,呵呵......),无法证明能运行通过。

AcGeCurve2d *geCurve1,*geCurve2;
AcGePointOnCurve2d zjPt1,zjPt2;//该类派生自AcGePointEnt2d,
                           //与AcGePoint2d有很大不同,后面将看到如何转换
geCurve1->getClosestPointTo(*geCurve2,zjPt1,zjPt2,AcGeContext::gTol);
    //加上最后一个参数是我个人编程习惯,你不一定要这样做。
    //我的目的是为了使自己知道系统不会调用另一个三参数的函数重载版本。
AcGePoint2d pt1,pt2;
pt1 = zjPt1.point();   //AcGePointOnCurve2d::point()函数返回AcGePoint2d点坐标。
pt2 = zjPt2.point();

lihongyu2467 发表于 2003-10-22 20:38:00

多谢版主的耐心解答。
页: [1]
查看完整版本: [求助]看看getClosestPointTo函数的使用