这是测试代码:
#include "stdafx.h"
#include<conio.h>
class clsA
{
public:
void Test()
{
printf("aaa");
}
};int _tmain(int argc, _TCHAR* argv[])
{
clsA *t=NULL;
t->Test();
char ch;
ch=getchar();
return 0;
}上边能输出 aaa
我不明白了啊.当然如果不在上边
clsA *t=NULL;写成这样会报错.
Run-Time Check Failure #3 - The variable 't' is being used without being defined.
都可以编译通过.哪位大哥来说一下这其中的机制啊...我糊涂了.
#include "stdafx.h"
#include<conio.h>
class clsA
{
public:
void Test()
{
printf("aaa");
}
};int _tmain(int argc, _TCHAR* argv[])
{
clsA *t=NULL;
t->Test();
char ch;
ch=getchar();
return 0;
}上边能输出 aaa
我不明白了啊.当然如果不在上边
clsA *t=NULL;写成这样会报错.
Run-Time Check Failure #3 - The variable 't' is being used without being defined.
都可以编译通过.哪位大哥来说一下这其中的机制啊...我糊涂了.
如果你在函数里使用成员变量,很可能就crash了
void clsA::Test()可以想象成编译生成一个void TestProxy(clsA* pClass){}的函数,其中第一个参数为clsA* this。。
t->Test(); → TestProxy(t)
由于Test不需要访问t的实际内容,等价于参数不起作用
有啥区别?那我不明白它是咋找到这个方法的地址的....不是 =null莫?或者方法的地址保存在类里了.哎.学的越多就发现.懂的更少.....
那个runtimecheck可以忽略