ex210.cpp
资源名称:VC6.0.rar [点击查看]
上传用户:qdhmjx
上传日期:2022-07-11
资源大小:2226k
文件大小:1k
源码类别:
书籍源码
开发平台:
Visual C++
- #include <iostream.h>
- class CPoint
- {
- public:
- CPoint()
- {
- m_x=m_y=0;
- }
- CPoint(unsigned x,unsigned y)
- {
- m_x=x;
- m_y=y;
- }
- void Print()
- {
- cout<<"Point("<<m_x<<","<<m_y<< ")"<<endl ;
- }
- friend CPoint Inflate(CPoint &pt,int Offset);//声明一个友元函数
- private:
- unsigned m_x,m_y;
- };
- CPoint Inflate(CPoint &pt,int nOffset)//友元函数的定义
- {
- CPoint ptTemp=pt;
- ptTemp.m_x+=nOffset; //直接改变私有数据成员m_x
- ptTemp.m_y+=nOffset;
- return ptTemp;
- }
- void main()
- {
- CPoint pt(10,20);
- pt.Print();
- pt=Inflate(pt,3); //调用友元函数
- pt.Print();
- }