[c++]this指针理解
2020-11-28 01:57
阅读:789
标签:style blog class code java c

#includeusing namespace std; /** * this 指针理解 */ class A{ int i; public: void hello(){ cout"Hello"endl; } }; int main(){ A *p=NULL; p->hello(); }

由于单独开发基于c++的编译器,c++程序翻译成c程序后在,在使用c语言的编译器进行编译.
p->hello();
翻译为C程序为
hello(p);等价于hello(this);所以在调用hello后,程序并不会报错,而是正常执行.
但如果将hello()改为如下
void hello(){ cout"Hello"endl; }
那么程序将报错.
[c++]this指针理解,搜素材,soscw.com
[c++]this指针理解
标签:style blog class code java c
原文地址:http://www.cnblogs.com/heidsoft/p/3704066.html
上一篇:最常用的两种C++序列化方案的使用心得(protobuf和boost serialization)
下一篇:python报错 IndentationError: unindent does not match any outer indentation level
评论
亲,登录后才可以留言!