Android 智能指针学习 一
Android5.1 中智能指针涉及的文件如下:
system/core/include/utils/RefBase.h
system/core/libutils/RefBase.cpp
system/core/include/utils/StrongPointer.h
在学习Android的智能指针时,对于模板的使用不太清楚,于是我将sp类精简了一下,大概看一下在赋值和初始化的时候的函数调用关系:
- #include <iostream>
- using namespace std;
- template<typename T>
- class sp {
- public:
- inline sp() {};
- sp(T* other);
- sp(const sp<T>& other);
- template<typename U> sp(U* other);
- template<typename U> sp(const sp<U>& other);
- ~sp();
- sp& operator = (T* other);
- sp& operator = (const sp<T>& other);
- template<typename U> sp& operator = (const sp<U>& other);
- template<typename U> sp& operator = (U* other);
- };
- template<typename T>
- sp<T>::sp(T* other) {
- cout << "enter sp(T* other) " << endl;
- }
- template<typename T>
- sp<T>::sp(const sp<T>& other) {
- cout << "enter sp(const sp<T>& other) " << endl;
- }
- template<typename T> template<typename U>
- sp<T>::sp(U* other) {
- cout << "enter sp(U *other) " << endl;
- }
- template<typename T> template<typename U>
- sp<T>::sp(const sp<U>& other) {
- cout << "sp(const sp<U& other>)" << endl;
- }
- template<typename T>
- sp<T>::~sp() {
- }
- template<typename T>
- sp<T>& sp<T>::operator =(T* other) {
- cout << "enter operator =(T* other) " << endl;
- return *this;
- }
- template<typename T>
- sp<T>& sp<T>::operator =(const sp<T>& other) {
- cout << "enter operator = (const sp<T>& other)" << endl;
- return *this;
- }
- template<typename T> template<typename U>
- sp<T>& sp<T>::operator =(const sp<U>& other) {
- cout << "operator = (const sp<U>& other)" << endl;
- return *this;
- }
- template<typename T> template<typename U>
- sp<T>& sp<T>::operator =(U* other) {
- cout << "operator = (U* other)" << endl;
- return *this;
- }
- class Peng{
- };
- class Dong {
- };
- int main(int argc, const char *argv[])
- {
- Peng *p = new Peng();
- Dong *d = new Dong();
- cout << "---- sp<Peng> q = p ----" << endl;
- sp<Peng> q = p;
- cout << "\n---- sp<Peng> r(p) ----" << endl;
- sp<Peng> r(p);
- cout << "\n---- sp<Peng> b(r) ----" << endl;
- sp<Peng> b(r);
- cout << "\n---- sp<Peng> t; ----" << endl;
- sp<Peng> t;
- cout << "\n---- t = p ----" << endl;
- t = p;
- cout << "\n---- sp<Peng> a; ----" << endl;
- sp<Peng> a;
- cout << "\n---- a = t ----" << endl;
- a = t;
- Dong *c = new Dong();
- cout << "\n---- sp<Dong> e = c ----" << endl;
- sp<Dong> e = c;
- cout << "\n---- a = e ----" << endl;
- a = e;
- cout << "\n---- a = c ----" << endl;
- a = c;
- cout << "\n---- sp<Dong> e1(e) ----" << endl;
- sp<Peng> e1(e);
- cout << endl << endl;
- return ;
- }
下面是在PC机上的运行结果:
- pengdl@pengdl-HP:~/work/study/c++$ ./a.out
- ---- sp<Peng> q = p ----
- enter sp(T* other)
- ---- sp<Peng> r(p) ----
- enter sp(T* other)
- ---- sp<Peng> b(r) ----
- enter sp(const sp<T>& other)
- ---- sp<Peng> t; ----
- ---- t = p ----
- enter operator =(T* other)
- ---- sp<Peng> a; ----
- ---- a = t ----
- enter operator = (const sp<T>& other)
- ---- sp<Dong> e = c ----
- enter sp(T* other)
- ---- a = e ----
- operator = (const sp<U>& other)
- ---- a = c ----
- operator = (U* other)
- ---- sp<Dong> e1(e) ----
- sp(const sp<U& other>)
完。
Android 智能指针学习 一的更多相关文章
- android 智能指针的学习先看邓凡平的书扫盲 再看前面两片博客提升
android 智能指针的学习先看邓凡平的书扫盲 再看前面两片博客提升
- Qt 智能指针学习(7种指针)
Qt 智能指针学习 转载自:http://blog.csdn.net/dbzhang800/article/details/6403285 从内存泄露开始? 很简单的入门程序,应该比较熟悉吧 ^_^ ...
- Android结构分析Android智能指针(两)
笔者:刘蒿羽 博客:http://blog.csdn.net/liuhaoyutz Android版本号:4.4.2 在上一篇文章中,我们分析了Android智能指针中的强指针sp,本文我们来分析弱指 ...
- Android智能指针SP WP使用方法介绍
Android手机操作系统既然是开源的操作系统.那么在具体的文件夹中就会存放着各种相关功能的开源代码.我们在使用的时候可以根据这些源代码进行相应的修改就能轻松的完成我们所需的功能.在这里大家就一起来看 ...
- Android智能指针sp wp详解
研究Android的时候,经常会遇到sp.wp的东西,网上一搜,原来是android封装了c++中对象回收机制.说明:1. 如果一个类想使用智能指针,那么必须满足下面两个条件: a. 该类是虚基 ...
- Qt 智能指针学习(7种QT的特有指针)
从内存泄露开始? 很简单的入门程序,应该比较熟悉吧 ^_^ #include <QApplication> #include <QLabel> int main(int arg ...
- Qt 智能指针学习(7种QT智能指针和4种std智能指针)
从内存泄露开始? 很简单的入门程序,应该比较熟悉吧 ^_^ #include <QApplication> #include <QLabel> int main(int arg ...
- Qt 智能指针学习
原地址:http://blog.csdn.net/dbzhang800/article/details/6403285 从内存泄露开始? 很简单的入门程序,应该比较熟悉吧 ^_^ #include & ...
- [转]Qt 智能指针学习
从内存泄露开始? 很简单的入门程序,应该比较熟悉吧 ^_^ #include <QApplication> #include <QLabel> int main(int arg ...
随机推荐
- 记录一次Nginx跳转报错的问题
错误信息如下: An error occurred. Sorry, the page you are looking for is currently unavailable. Please try ...
- RGB颜色原理
参考:http://www.cnblogs.com/harrytian/archive/2012/12/12/2814210.html 工作中经常和颜色打交道,但却从来没有从原理上了解一下,这篇文章希 ...
- AE特效-与MAYA的结合、制作音乐舞蹈太极动作
http://blog.sina.com.cn/s/blog_a439a2670101fbkk.html AE特效-与MAYA的结合.制作音乐舞蹈太极动作 (2013-07-24 14:44:12) ...
- vbs登陆网站
Option Explicit Dim objIE Set objIE = CreateObject("InternetExplorer.Application") objIE.V ...
- bp神经网络模型推导与c语言实现(转载)
转载出处:http://www.cnblogs.com/jzhlin/archive/2012/07/28/bp.html BP 神经网络中的 BP 为 Back Propagation 的简写,最 ...
- 表单文件上传,ajax文件上传
原创链接:http://www.cnblogs.com/yanqin/p/5345562.html html代码 index.jsp(表单文件上传) <form action="sh ...
- [译]lambda表达式对 SAM (单个抽象方法类)type的处理方式
在阅读Venkat Subramaniam的著作<Functional Programming in Java> 之后,方法模式和lambda完美结合让我印象深刻. 这种模式经常用作数据源 ...
- 区块链开发(六)truffle使用入门和testrpc安装
在上篇博文中我们已经成功安装了truffle及所需相关环境,此篇就简单介绍一些truffle的使用及目录结构等. 简介truffle和testrpc truffle是本地的用来编译.部署智能合约的工具 ...
- ORM-老师信息系统
老师信息管理 思考 三种方式创建多对多外键方式及其优缺点. 通过外键创建 (自定义第三张表,通过外键与其他两张表关联 但是不能用Django ORM 多对多操作的语法) class Class(mo ...
- debian 更换sh的默认链接为bash
https://blog.csdn.net/mudongliangabcd/article/details/43458895