#include<iostream>
using namespace std;
class Test {
public:
Test(int a=, int b=)
{
this->a = a;
this->b = b;
}
Test & add_menber(Test &t2)
{
this->a += t2.a;
this->b += t2.b;
return *this;
}
void printf(Test &t)
{
cout << "a="<<t.a << "b=" << t.b << endl;
}
~Test()
{ }
//private://全局函数如果不是友元函数不能访问私有属性
int a;
int b; };
Test add(Test &t1, Test &t2)
{
Test temp;
temp.a= t1.a + t2.a;
temp.b = t1.b + t2.b;
return temp;
}
int main()
{
Test t1(, ), t2(, ), t3;
t3 = add(t1, t2);
cout << "t3.a="<<t3.a<<"t3.b="<<t3.b << endl; Test t4(, ),t5(,);
t4.printf(t4.add_menber(t5));
cout << "hello world!\n";
return ;
}

summary:

非静态成员函数有this指针,这样的成员函数实现参数会比全局函数少一个,反之全局函数参数会比非静态成员函数多一个。c++中多使用引用更好。

最新文章

  1. SpringMVC下Ajax请求的方法,@Responsebody如果返回的是布尔值,ajax不会接到任何回传数据
  2. 创建文本注记TextElement
  3. WNDR3700V4 安装SVN Server
  4. Redis简介
  5. js面向对象组件
  6. 网站压力测试工具webbench
  7. Visual studio 2013的安装和单元测试
  8. solr5.5教程-tomcat布署
  9. 《APUE》第四章笔记(3)
  10. Java序列化技术
  11. 如何修复在Microsoft Azure中“虚拟机防火墙打开,关闭RDP的连接端口”问题
  12. 100个精选zencart扩展插件
  13. SDN学习之实现环路通信
  14. 应用教程之帕克西AR虚拟试妆3D动态美妆
  15. MyBatis_关联关系查询
  16. Uva 12171 Sculpture - 离散化 + floodfill
  17. HTTPS介绍
  18. JS _函数作用域及变量提升
  19. Emacs中多个golang项目的配置方法
  20. Openldap命令详解

热门文章

  1. UsageLog4j
  2. 简单四步開始树莓派上的Docker之旅
  3. OpenWrt的开机启动服务(init scripts)
  4. XMLHttpRequest cannot load ...谷歌浏览器跨域问题
  5. PHP 多个mysql连接的问题
  6. dokuwiki语法
  7. eclipse修改文件编码
  8. Eclipse智能提示设置
  9. RHEL7虚拟机添加新网卡后,网卡无法启动
  10. Android多点触摸放大缩小图片