Skip to content

Last updated:2026-10-12

C++ Dereference Operator *

0. Introduction

When we work with pointers, we usually use *, for example:

int a = 1;
int *ptr = a;
std::cout << *ptr << std::endl;

Beyond that, does it have any other uses?

The answer is yes; for example, in C++ there are also the following three:

  • ::*
  • .*
  • ->*

So do you know what each of these three means?

1. ::*

::* is called the Pointer to member declarator.

Let me give an example:

In the example below, how would you take the address of w_?

If you write double * d = &w_; that is invalid, because it is not known where w_ lives, so you need a pointer to member declarator; that makes the binding possible, and once you have this pointer you can access the member. Let's continue with the other two.

class Rectangle {
 public:
  double w_, h_;

  Rectangle(double w, double h) : w_(w), h_(h) {}
  double area() { return w_ * h_; }
};

int main() {
  Rectangle r{2.1, 3.2};
  double Rectangle::* w = &Rectangle::w_;
  r.*w = 2.2;
  std::cout << r.w_ << std::endl;
};

2. .*

.* is called pointer to member of object. This one is fairly easy to understand: it is the pointer for accessing a member of an object; a pointer to member lets you refer to non-static members of a class object. You cannot use a pointer to member to point to a static class member, because the address of a static member is not associated with any particular object.

So, in the example above, this line of code changes the value of member w to 2.2.

r.*w = 2.2;

3. ->*

->* is called pointer to member of pointer. This one is even easier to understand: it is similar to ., except that it operates on the address of a member of a **pointer object*,

so the corresponding example becomes:

Rectangle r{2.1, 3.2}, *pr;
pr = &r;
std::cout << pr->*w << std::endl;

For more details, please read cppreference.com.

https://en.cppreference.com/w/cpp/language/pointer#Pointers_to_members

Did you get it? End of this section~

Comments