C ++ object-oriented Review (4) -- Application of pointer in Object-Oriented

Source: Internet
Author: User

In fact, the overload of the constructor is nothing more than implementing the definition of several functions, and then specifying different parameters. The simplicity is not reflected in the definition, but in the use. Only one function name is called, you can perform different operations.

Pointer in Object-Oriented:

Pointer to the object;

Time * PT

Time T1;

PT = & T1;

Here is the definition method of the pointer to the object in the object-oriented pointer.

Pointer to an object Member

Pointer data type name * pointer variable name pointing to object members

For example, P1 = & ti. Hour cout <* P1 <Endl;

(2) pointer data type name * (pointer variable name) (parameter variable) pointing to the member function)

For example, void (* p) (); // P is a pointer variable pointing to the void type.

It can point to a function and call the function through the pointer variable:

P = fun; // pay the function entry address to the pointer Variable P, and P points to the function fun.

(* P) (); // call the fun Function

(The biggest difference between a member function and a common function is that it is a member of a class.

The compilation system requires three matching measures when compiling pointer and function assignment:

Function parameter type and number of parameters & function return value & Class

)

(3) the pointer variable that defines the function pointing to the common member function is generally formatted

Data Type name (Class Name: * p) (parameter list)

Void (Time: * P3) (); // defines the pointer variable pointing to the time class shared member function

P3 = & time: get_time; // Let the pointer P3 point to the time class public member function get_time

(The preceding two sentences can be combined into one line: void (Time: * P3) () = & time: get_time)

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.