[c++]this指针理解
2014-05-02 15:04
239 查看
#include <iostream> using 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<<i<<"Hello"<<endl; }
那么程序将报错.
相关文章推荐
- C++:this指针的简单理解
- C++中this指针的理解
- c++ 中的this指针的理解和用法
- C++中this指针的理解及用法
- C++中this指针的理解
- 理解C++中的this指针
- C++中关于this指针的理解
- C++中this指针的理解和用法
- C++中this指针的理解和用法
- [转]C++中this指针理解汇总以及问题和解答
- C++中this指针的理解和用法
- C++中this指针理解
- c++ this 指针的理解
- C++中this指针的理解
- C++对This指针的理解
- C++中this指针的形象理解
- C_C++ _________________this指针----类的理解
- C++中this指针的理解和用法
- c++中this指针的理解及其用法
- C++中this指针的理解和用法