The static member function cannot call the Non-static member function

Source: Internet
Author: User

1 General class static member functions cannot call non-static member functions

2 can a static member function call a constructor?

The answer is yes, because the static member function does not have this pointer, the general static member function cannot access the Non-static member, including member functions and member variables.

Because of the particularity of the constructor, it constructs an object from scratch, so calling it does not require a instance, that is, it does not require the this pointer to be called, so the constructor can be called in the static function.
The O constructor is divided into two stages:
1. Allocating memory: This is the beginning of the phase, the end of the phase, resulting in a instance, also known as this.
2. Initialize Memory: the part that actually calls the constructor. The constructor is already called on the instance, so any non-static functions can be called.
o in a static function, as long as it is through instance. Func () or Pointer->func () can call a non-static function because this is explicitly specified.
Therefore, it is advocated to display the use of this in all non-static member functions using the member.

The static member function cannot call the Non-static member function

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.