Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does static_cast mean when it's followed by two pairs of parentheses?

What does this say:

return static_cast<Hasher &>(*this)(key);

?

I can't tell whether *this or key is passed to static_cast. I looked around and found this answer, but unlike what I'm stuck on, there's nothing inside the first pair of parentheses.

like image 792
johnsmith Avatar asked Nov 26 '25 00:11

johnsmith


1 Answers

The statement is parsed as

return (static_cast<Hasher &>(*this))(key);

So, the argument to static_cast is *this. Then the result of the cast, let's call it x, is used as postfix-expression in a function call with key as argument, i.e. x(key), the result of which is returned.

like image 186
user17732522 Avatar answered Nov 28 '25 15:11

user17732522



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!