为结构体类型赋值的操作

来源:互联网 发布:户外运动现在数据分析 编辑:程序博客网 时间:2024/05/16 07:33

#include "stdafx.h"

 

typedef struct A
{
    A(){}


    A(const A& another)
   {
      a = another.a;
      b = another.b;
      c = another.c;
      d = another.d;
   }

 

    A operator= (const A& another)
   {
      a = another.a;
      b = another.b;
      c = another.c;
      d = another.d;
      return (*this);
    }

 

    int a;
    double b;
    int c;
    double d;
} AAA;


int _tmain(int argc, _TCHAR* argv[])
{
    AAA first;

    first.a = -3;
    first.b = -2.5;
    first.c = -2;
    first.d = -1.5;

 

    AAA second(first);

    second = first;

   

    return 0;
}

 

通过打断点,可以看出 直接用引用 和用“=”赋值的不同。

 

原创粉丝点击