Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange asterisk use while dereferencing [duplicate]

I came across code today that looked like:

result = (this->*(*c))(&param)

The main part that confuses me is the this->*(*c) What does it mean to have the asterisk operators between the arrow (->) and the name of the variable we're accessing (c).

like image 223
turbulencetoo Avatar asked Dec 08 '25 19:12

turbulencetoo


1 Answers

What you have here is an operator which you don't see very often.

->* is a single operator. It is the pointer-based counterpart to .* and is a member access operator.

It is used if you have an object to use a member on (e.g. a function), but don't know the concrete member (it's stored in a variable).

Let's split it up:

this      // object to work on
->*       // member access operator
(*c)      // dereference pointer pointing to member function (c is a pointer-to-pointer)
(&param)  // call member function stored in c on this passing &param to the function

See also: http://en.cppreference.com/w/cpp/language/operator_member_access

Edit: This post also contains a good explaination on what is happening here: https://stackoverflow.com/a/6586248/1314789

like image 124
Excelcius Avatar answered Dec 11 '25 08:12

Excelcius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!