Here is a small example to illustrate how member functions are called in c ++.
# Include
Using namespace std; class Test {public: void funcMember () {cout <"I'm member function" <endl; int * ptr = reinterpret_cast
(Const_cast
(This); // int * ptr = (int *) (const_cast
(This); cout <* ptr <endl; // Why is it int x; int y; there are eight bytes of cc in the middle of the stack, which should be x, and y is next to ptr + = 3; // Therefore, three cout <* ptr <endl; ptr + = 3; cout <* ptr <endl; ptr + = 3; cout <* ptr <endl; ptr + = 3; cout <* ptr <endl;} Test (): x (3) {} int x ;}; int main () {Test * t = NULL, * ptr; int x = 10; int y = 20; int z = 30; int zz = 40; Test tt; // t-> funcMember (); ptr = & tt; ptr-> funcMember (); cout <"------------------------" <endl; tt. funcMember (); return 0 ;}
First, let's explain why t is a null pointer to the commented out part. This call is still successful.
Please refer to the results after Disassembly
Therefore, the first part of the red line is omitted.
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + xMfU2b + 0sbvXosrNtfS687PM0PK1xNTL0NC94bn7yOe6zsTYo788L3A + CjxwPjxpbWcgc3JjPQ = "http://www.2cto.com/uploadfile/Collfiles/20140509/20140509091953256.jpg" alt = "">
It can be seen from the results that the instance of the object is passed into the function as an address, so as long as this address is not used, no matter whether it is empty or not, it will not be wrong, if you use what you have done in this example,
You can also flexibly change the cause.