求一个 = 赋值号 运算符重载函数
typedef struct FPointtag
{  
   float x, y;
}FPoint我想使
FPoint a;
CPoint b;
a =b
成为可能应该怎样写?

解决方案 »

  1.   

    写个函数把FPoint中的每个变量再copy一遍
    我觉得用指针比较好
    不过好象struct结构自己会把a中的每一项给b的
      

  2.   

    typedef struct FPointtag
    {  
       float x, y;
       BOOL operate = (CPoint p);
      {
         x = p.x;
         y = p.y
      }
    }FPoint
    不知道对不对,你试试先。
      

  3.   

    frient FPoint operator = (FPoint& fpt, CPoint& cpt)
    {
        fpt.x = cpt.x; 
        fpt.y = cpt.y;
        return FPoint(fpt.x,fpt.y);
    }
      

  4.   

    akademecia(你不说我倒还明白,你越说我越糊涂) 的代码无法通过编译
      

  5.   

    class FPoint 
    {  
       float x, y;
    public:
       void operator=(CPoint& p)
      {
         x = float(p.x);
         y = float(p.y);
      }
    };
    我测过,OK!
      

  6.   

    uhlan(uhlan) 果然有天才!
    typedef struct FPoint2Dtag
    {
    float x;
    float y;

    void operator =(const CPoint &Point) 
    { x = (float)Point.x;
    y = (float)Point.y;
    }}FPoint2D;
    也能够通过编译,并且运行正常,还请各位帮忙看看有没有潜在错误。
      

  7.   

    uhlan(uhlan) 的代码是对的。但是这个类毫无用处。
      

  8.   

    可是可以实现赋值!
    比如CPoint s1; FPoint f2;
    f2 = s1;
    可以正常实现。
      

  9.   

    uhlan(uhlan) 的代码是对的,但无法实现这样的赋值。
    FPoint f1,f2;
    CPoint c1;
    f2 = f1 = c1;
      

  10.   

    class FPoint 
    {  
       float x, y;
    public:
       void operator=(CPoint& p)
      {
         x = float(p.x);
         y = float(p.y);
      }
      void operator=(FPoint& pt)
      {
        x=float(pt.x);
        y=float(pt.y);
      }};
    实现
    FPoint f1,f2;
    CPoint c1;
     f1 = c1;
    f2 =f1