C + + this pointer

Source: Internet
Author: User

Understand the meaning of class first. Class should be understood as a type, like Int,char, as a user-defined type. Use this type to declare a variable, such as int x, MyClass my, and so on. This is like the variable x has an int type, and the variable my has the MyClass type. If you understand this, it's good to explain this, and this is the pointer to my. If there is another variable MyClass mz,mz This is a pointer to MZ. This makes it easy to understand that the type of this should be MyClass *, and that its dereference *this should be a variable of type MyClass. The type variable itself is usually used when the class is defined, because at this time the variable name is not known (it is not possible to fix the actual variable name for general purpose), and the variable itself is used with a pointer like this.

I wrote the blog myself in C + + CPP and HPP, with an example:

. h Code:

#ifndef Circle_h
#define Circle_h

Class Circle
{
Private
Double r;//radius
Public
Circle ();//constructor
Circle (double R);//constructor
Double area ();
};

#endif

. cpp Code;

#include "Circle.h"

Circle::circle ()
{
this->r=5.0;
}

Circle::circle (double R)
{
this->r=r;
}

Double Circle:: Area ()
{
return 3.14*r*r;
}

This allows you to understand this pointer.

Https://www.cnblogs.com/liushui-sky/p/5802981.html

C + + this pointer

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.