What Is the Dereference Operator?

Structure dereference operator, also known as element selection through pointer, is an operator in C and C ++. Its function is to get a member of the object pointed to by the pointer to the left of the operator. This operator has a higher priority, and is the same as the function call operator, array index operator, and member selection operator by reference. It is also combined from left to right.

The structure dereference operator is a
C language specifies these 34 operators with different priority levels and
  #include <iostream>


 class foo
 {
 public:
 void func () {
 std :: cout << "foo say hello" << std :: endl;
 }
 };
 class bar
 {
 foo a;
 public:
 foo * operator-> () {
 return & a;
 }
 void func () {
 std :: cout << "bar said hello" << std :: endl;
 }
 };
 class D
 {
 bar b;
 public:
 bar operator-> () {
 return b;
 }
 void func () {
 std :: cout << "D said hello" << std :: endl;
 }
 };

 int main ()
 {
 D dumb, * pd = & dumb;
 pd-> func (); // pc is a pointer to a class, so directly dereference D d;
 d-> func (); // d is not a pointer type, so D :: operator-> () overloaded version is called}

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?