In C ++, what does this construct mean, "InterceptionKeyStroke & kstroke = * (InterceptionKeyStroke *) & stroke"?

I am new to C ++ and don't understand this construct.

InterceptionKeyStroke &kstroke = * (InterceptionKeyStroke *) &stroke

I know that and = pointer. But what does this mean?

* (InterceptionKeyStroke *)
+4
source share
2 answers

Destruction:

InterceptionKeyStroke     // a type...
&                         // ...which is by reference
kstroke                   // named 'kstroke'
=                         // bound to (since references are bound)
*                         // something that a pointer points to
(InterceptionKeyStroke*)  // "I know what the type is!" cast
&                         // address of...
stroke                    // ...variable named 'stroke'

So it *(InterceptionKeyStroke*)goes to the pointer and then dereferences the pointer.

+9
source

I know that and = pointer.

Your knowledge is incomplete. &has several meanings in C ++. &the one you are referencing is an operator address, as in:

int i = 0;
int* ptr = &i; // `ptr` contains address of `i`

InterceptionKeyStroke &kstroke, & , &, , * (InterceptionKeyStroke *) &stroke, , .

?

* (InterceptionKeyStroke *)

C-, , , InterceptionKeyStroke *. * , InterceptionKeyStroke.

, InterceptionKeyStroke &kstroke = * (InterceptionKeyStroke *) &stroke , :

" kstroke - InterceptionKeyStroke, . , , , , InterceptionKeyStroke , , , InterceptionKeyStroke, , . , InterceptionKeyStroke, , , , ."

, . stroke InterceptionKeyStroke ? InterceptionKeyStroke stroke? , undefined , C- . , .

+4

Source: https://habr.com/ru/post/1695276/


All Articles