C ++ learning summary_this pointer

Source: Internet
Author: User

I,

The object is in the heap.ProgramManually released the memory.
When the object is in the stack, the system automatically releases the memory after the program runs.
This variable records the memory address of each object and then uses the indirect operator-> to access its members.
This variable records the memory address of each individual object, and this Pointer Points to each individual object, so
The memory address of this variable output by different objects is also different.
This variable stores the object address, so this pointer is the pointer to the object.
This pointer is created and deleted by the compiler.

2. The following is an example:

# Include <stdlib. h>
# Include <iostream>
Using namespace STD;
Class
{
Public:
A () {cout <"memory address of this variable:" <This <Endl ;}
Int get_number () const {return number ;}
Void set_number (int x) {number = x ;}
PRIVATE:
Int number;
};
Int main ()
{
A;
Cout <"& A:" <& A <Endl;
A. set_number (100 );
Cout <"a. I:" <A. get_number () <Endl;
A B;
Cout <"& B:" <& B <Endl;
B. set_number (1000 );
Cout <"B. I:" <B. get_number () <Endl;
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.