c++ this *this
在一个类里每个成员函数都有一个this指针。this指针指向调用对象。如果方法需要引用整个调用
对象可以使用*this。this是对象的地址,而不是对象本身。
*this是对象本身。可以将*this 作为调用对象的别名
Stock::Stock(const std::string &name)
{
this->m_company=name;
(*this).m_company="";
}
class A
{
public:
A()
{
this->m_i = ;
}
A &Fun()
{
return *this;
}
private:
int m_i;
};
this 这是指代本对象
this本来是个指针,*this的星号是取指针指向的内容,
所以,*this是整个对象,而this是指向本对象的指针
随机推荐
- Windows Phone 8.0 SDK Update(10322) Released
昨天微软低调发布了WP 8 SDK的更新,甚至在Windows Phone Developer Blog上都没有提及. 从开发者的角度来看,此次更新的确没有太多需要关注的地方,因为没有添加新的API和 ...
- .net开发windows服务小结
今天学习了在.net下创建一个windows服务,总结一下学习心得. 开发环境:visual studio 2012 一.编写程序 (1)创建一个空解决方法 (2)添加一个控制台应 ...
- Java AIO 异步IO应用实例
项目地址:https://github.com/windwant/aio-test Server: package org.windwant.aio; import java.io.IOExcepti ...
- Remote Desktop File Format
转自:http://engrmosaic.uncc.edu/mosaic-anywhere/remote-desktop-file-format The new Terminal Services c ...
- linux的“自动化”
h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h ...
- javax.servlet.ServletException cannot be resolved to a type错误解决方法
在页面中使用全局路径时${pageContext.request.contextPath}出现javax.servlet.ServletException cannot be resolved to ...
- CentOS下mysql默认安装位置
如果采用RPM包安装,安装路径应在/usr/share/mysql目录下 mysqldump文件位置:/usr/bin/mysqldump mysqli配置文件: /etc/my.cnf或/usr/s ...
- 新手ui设计师必备——切图规范
图文并茂,浅显易懂. 使用markman标注. 资源链接: 图片来自http://www.ui.cn/detail/56347.html 本文作者starof,因知识本身在变化,作者也在不断学习成长, ...
- [转]学习Nop中Routes的使用
本文转自:http://www.cnblogs.com/miku/archive/2012/09/27/2706276.html 1. 映射路由 大型MVC项目为了扩展性,可维护性不能像一般项目在Gl ...
- 谈谈Lucene和Solr索引存目录
在Lucene中,有几种索引存放模式呢?用过的人可能记得SimpleFSDirectory.MMapDirectory.NIOFSDirectory.RAMDirectory这四种.新版本的通过FSD ...