#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;
}

那么程序将报错.

posted on 2014-05-02 15:04  heidsoft  阅读(250)  评论(0编辑  收藏  举报