#include <iostream>
#include<algorithm>
using namespace std; class Test { public:
Test(int num) {
this->num = num;
} public:
int num;
};
//引用
void change0(Test& t) {
t.num = 2;
Test temp(3);
t=temp;
Test test(4);
t=test;
// t = new Test(3); // 报错
}
//指向指针的引用
void change1(Test* & t) {
t->num = 2;
t = new Test(3);
}
//指针
void change2(Test *t) {
Test *a=t;
cout<<t<<" "<<&t<<" "<<(*t).num<<endl;//t表示指针里存的值即指向的对象的地址,&t表示指针自身的地址,*t表示指向的对象的值
t->num = 2;
t = new Test(3); // 指针再次赋值,指向新内存
} int main(int argc, char const *argv[])
{ Test t3(1);
cout << "------引用---------" << endl;
cout << t3.num << endl;
change0(t3);
cout << t3.num << endl; Test *t2 = new Test(1);
cout << "------指针---------" << endl;
cout << t2->num << endl;
change2(t2);
cout << t2->num << endl; Test *t = new Test(1);
cout << "------指针的引用---------" << endl;
cout << t->num << endl;
change1(t);
cout << t->num << endl;
system("pause");
return 0;
}

最新文章

  1. 怎样设置才能允许外网访问MySQL
  2. 2016HUAS暑假集训训练2 F - A Simple Problem with Integers
  3. 解决 RHEL 7/ CentOS 7/Fedora 出现Unit iptables.service failed to load
  4. PHP7革新与性能优化
  5. noi 7627 鸡蛋的硬度
  6. 调试mvc 源码【转:http://www.cnblogs.com/wucj/archive/2013/06/09/3128698.html】
  7. Excel数据链接取消
  8. Lua运算符
  9. HDU 4005 The war (图论-tarjan)
  10. ValueError: Cannot feed value of shape ..
  11. 牛客练习赛35-背单词-线性DP
  12. 最全的MonkeyRunner自动化测试从入门到精通(9)
  13. epoll的由来
  14. Java数组逆序排列
  15. Nginx安装使用及与tomcat实现负载均衡
  16. telnet 163发送邮件
  17. SQL中Union和UnionAll的使用
  18. python-day11--函数
  19. exception processing, template error resolving template
  20. uva 701 - The Archeologists&#39; Dilemma

热门文章

  1. A - 敌兵布阵 ——B - I Hate It——C - A Simple Problem with Integers(线段树)
  2. LianLianKan HDU - 4272 状压dp
  3. - 迷宫问题 POJ - 3984 bfs记录路径并输出最短路径
  4. WPF 只读集合在 XAML 中的绑定(WPF:Binding for readonly collection in xaml)
  5. K8S(04)核心插件-coredns服务
  6. 二进制方式安装docker(非root用户启动docker)
  7. Java RMI 实现一个简单的GFS(谷歌文件系统)——介绍篇
  8. RT-Thread学习笔记2-互斥量与信号量
  9. ES6 version repeatify
  10. HTML Custom Elements (v1)