linvoker linvoker - 1 year ago 83
C++ Question

What is "operator .* " in C++?

This operator is mentioned in C++ Primer 5th . The book introduces hardly anything about it.All I know about it is it can't be overloaded.

Then, what is it?And where can we use it?

Answer Source

The .* operator is used to dereference pointers to class members. The first operand must be of class type. If the type of the first operand is class type T, or is a class that has been derived from class type T, the second operand must be a pointer to a member of a class type T.

The .* operator bind the second operand to the first, resulting in an object or function of the type specified by the second operand.

If the result of .* is a function, you can only use the result as the operand for the ( ) (function call) operator. If the second operand is an lvalue, the result of .* is an lvalue.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download