C + + Common functions, ordinary member functions, static member functions of the difference __jquery

Source: Internet
Author: User

1 normal function: is a global function, not restricted by specific classes and objects, can be called directly.

For example:

void printf ()

{

printf ("Hello World");

}

2 Ordinary member function: C + + Normal member function is essentially a generic function that contains the this pointer to a specific object, that is, the normal member function of the C + + class implicitly contains a this pointer to the current object.

For example: Define a class:

Class MyClass

{

Public

void Myprint ()

{

printf ("m_a:%d", m_a);

}

Private

int m_a;

};

void Main ()

{

MyClass A1 (5);

A1.myprint ();

}

Call the normal member function inside the main function: A1.myprint () is equivalent to Myprint (&A1). This is because the C + + compiler implements ordinary member functions, the nature of Void Myclass::myprint () is the ordinary function void Myprint (MyClass *this);

3 Static member functions

First, the static member variable of a class is introduced: The data member in the class body is preceded by the static keyword, and the data member becomes the static data member of the class.

The nature of static member variables:

1 The static variable is initialized only once, and the next execution of the initialization statement is skipped directly.

2 Static Description A member of a class is a statically member, the member variable modified by static belongs to this class, no longer only belongs to the specific object.

Again, static member functions: the declaration of a member function in a class body, preceded by the static keyword, becomes a static member function of the class.

The nature of static member functions:

1 non-static members of the class can not be invoked.

2 static member functions do not contain this pointer. A static member function belongs to this class and is no longer just a specific object.

Therefore, the difference between a static member function of a class and a normal member function of a class is:

A static member function does not contain this pointer to a specific object;

The normal member function contains a this pointer to a specific object.

Related Article

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.