#include "stdafx.h"
#include "iostream"
class CMan
{
private:
int height;
int age;
public:
int getheight()const;
int getage()const;
CMan();
~CMan();
CMan operator +(CMan& one );
};CMan CMan::operator +(CMan& one ) //这个地方看不懂
{
CMan temp;
temp.age = age+one.getage();
temp.height = height+one.getheight();
return temp;
}CMan::CMan()
{
height = 100;
age= 10;
}CMan::~CMan()
{}int CMan::getage()const
{
return age ;
}int CMan::getheight()const
{
return height;
}int main(int argc, char* argv[])
{
CMan man1,man2,man3;
man3= man1+man2;
printf("%d",man3.getage());
printf("\n");
printf("%d",man3.getheight());
return 0;
}说明(执行顺序): /*
1,主函数先构造3个CMan对象, 分别为man1,man2, man3.
2,然后,通过man3=man1+man2后, 进入运算符重载函数 CMan CMan::operator +(CMan& one ) //这个地方看不懂
3,在第2步骤中, 再次构造对象temp, 最后将其返回。
4,不明白的地方是:
temp.age = age+one.getage();
temp.height = height+one.getheight();
中的age+one.getage()具体表示什么意思? 是哪一个是man1的age成员, 哪一个又是man2的age成员。
同理:height+one.getheight()也是一样的迷惑!!!
敬请回复, 谢谢!!!
*/
#include "iostream"
class CMan
{
private:
int height;
int age;
public:
int getheight()const;
int getage()const;
CMan();
~CMan();
CMan operator +(CMan& one );
};CMan CMan::operator +(CMan& one ) //这个地方看不懂
{
CMan temp;
temp.age = age+one.getage();
temp.height = height+one.getheight();
return temp;
}CMan::CMan()
{
height = 100;
age= 10;
}CMan::~CMan()
{}int CMan::getage()const
{
return age ;
}int CMan::getheight()const
{
return height;
}int main(int argc, char* argv[])
{
CMan man1,man2,man3;
man3= man1+man2;
printf("%d",man3.getage());
printf("\n");
printf("%d",man3.getheight());
return 0;
}说明(执行顺序): /*
1,主函数先构造3个CMan对象, 分别为man1,man2, man3.
2,然后,通过man3=man1+man2后, 进入运算符重载函数 CMan CMan::operator +(CMan& one ) //这个地方看不懂
3,在第2步骤中, 再次构造对象temp, 最后将其返回。
4,不明白的地方是:
temp.age = age+one.getage();
temp.height = height+one.getheight();
中的age+one.getage()具体表示什么意思? 是哪一个是man1的age成员, 哪一个又是man2的age成员。
同理:height+one.getheight()也是一样的迷惑!!!
敬请回复, 谢谢!!!
*/
解决方案 »
- ntdll! 7c92120e()求解决方法!
- 在页面中 如何从active(active中有个文本框)中获得数据 !!!!!!!!!!!
- 最简单的UDP通信失败!?
- 请问DECLARE_DYNAMIC和DECLARE_DYNCREATE的区别?
- =====初学者问两个控件的使用问题,很简单的=====
- 请问,我想从主窗口通过按钮呼出一个已经定义好的窗口,该怎么样做?给分。。。
- 请教,将"12345678910ca1212"这样的字符串右移1位?
- 那有UML的书,最好电子版,急急
- 被彻底删除的文件,如何编程实现恢复???
- 请问一个关于ole对象的小问题?
- 大牛,win32中ListView_DeleteAllItems()卡了,急需求解?(内附相关asm)
- WinMain里的WNDCLASS的窗口类名称为什么都用static修饰???
{
private:
int height;
int age;
public:
int getheight()const;
int getage()const;
CMan();
CMan::CMan(int a, int b);// 添加一个构造函数
~CMan();
CMan operator +(CMan& one );
};CMan CMan::operator +(CMan& one ) //这个地方看不懂
{
CMan temp;
temp.age = age+one.getage();
temp.height = height+one.getheight();
return temp;
}CMan::CMan()
{
height = 100;
age= 10;
}CMan::CMan(int a, int b)
{
height = a;
age= b;
}
CMan::~CMan()
{}int CMan::getage()const
{
return age ;
}int CMan::getheight()const
{
return height;
}int main(int argc, char* argv[])
{
CMan man1,man2(1,2),man3;
man3= man1+man2;
printf("%d",man3.getage());
printf("\n");
printf("%d",man3.getheight());
return 0;
}
{
age = age+one.getage();
height = height+one.getheight();
return *this;
}
中的age+one.getage()具体表示什么意思? 是哪一个是man1的age成员, 哪一个又是man2的age成员。
---------------------------------------
第一个age是man1的age的值,第二个调用得到的是man2的age的值。这个你Debug下调试看一下就清楚了