C 语言指针的一个小疑点
C 语言指针的一个小问题
俺有个指针的小问题,不太理解,望各位大侠赐教,感激不尽~~
#include <iostream>
using namespace std;
class GCC
{
public:
void test()
{
cout<<"this is the test"<<endl;
}
};
int main(int argc, const char * argv[]) {
GCC gccObj;
GCC *gccp = 0; // 或者 GCC *gccp = NULL:
(*gccp).test()
return EXIT_SUCCESS;
}
gccp 初始化为 NULL 指针,但是为啥空指针构造为 GCC 对象还可以调用 test() 方法捏?
------解决思路----------------------
结合this指针,可能比较容易理解:
http://blog.****.net/wz7654321/article/details/8375922
楼主的代码,调用test的时候,也传了个this指针进去,而且this是空指针。但是因为test函数根本就没用到任何成员变量,所以test函数里面根本就没有用到这个空的this指针,所以也就不会挂。
俺有个指针的小问题,不太理解,望各位大侠赐教,感激不尽~~
#include <iostream>
using namespace std;
class GCC
{
public:
void test()
{
cout<<"this is the test"<<endl;
}
};
int main(int argc, const char * argv[]) {
GCC gccObj;
GCC *gccp = 0; // 或者 GCC *gccp = NULL:
(*gccp).test()
return EXIT_SUCCESS;
}
gccp 初始化为 NULL 指针,但是为啥空指针构造为 GCC 对象还可以调用 test() 方法捏?
------解决思路----------------------
结合this指针,可能比较容易理解:
http://blog.****.net/wz7654321/article/details/8375922
楼主的代码,调用test的时候,也传了个this指针进去,而且this是空指针。但是因为test函数根本就没用到任何成员变量,所以test函数里面根本就没有用到这个空的this指针,所以也就不会挂。