Dripping Reverse-C ++ _ this pointer

1. Use the structure directly as the parameter \ pass the structure pointer

2. The size of the empty structure is 1

3. The function can be placed inside the structure or outside the structure

struct sclass
{
    int a;
    int b;
    int c;
    int d;

    int Plus(sclass* sc)
    {
        return sc->a + sc->b;
    }
};

The size of the detection structure is:

4. How to use the function in it

struct sclass
{
    int a;
    int b;
    int c;
    int d;

    int Plus(sclass* sc)
    {
        return sc->a + sc->b;
    }
};

int main(int argc, char* argv[])
{
    sclass s;
    s.a = 10;
    s.b = 20;

    int x = s.Plus(&s);

    printf("%d %x\n", x, sizeof(s));
    return 0;
}

5. Encapsulation, class, member function

Package:

a. Defining the function inside the structure is encapsulation.

b. The compiler will automatically pass the pointer of the structure to the function.

class:

Structures with functions are called classes.

Member functions:

The functions in the structure are called member functions.

6, this pointer

Features of this pointer:

a. You use it or not, it is there

b. When the number of parameters is determined, use ecx to pass

c. When the number of parameters is uncertain, the last one is passed (see variable length parameters)

7. Display using this pointer

The characteristics of this pointer:
a.this pointer can not do ++-wait for operation, can not be re-assigned.
b.this pointer does not occupy the width of the structure.
 

Published 20 original articles · Likes2 · Visits 634

Guess you like

Origin blog.csdn.net/z17805008775/article/details/105625567