在C++中,这种结构意味着"InterceptionKeyStroke&kstroke =*(InterceptionKeyStroke*)&stroke"?

Ale*_*Sv. 4 c++ pointers

我是C++的新手,不懂这个结构.

InterceptionKeyStroke &kstroke = * (InterceptionKeyStroke *) &stroke
Run Code Online (Sandbox Code Playgroud)

我知道&=指针.但是,这是什么意思?

* (InterceptionKeyStroke *)
Run Code Online (Sandbox Code Playgroud)

Elj*_*jay 9

打破它:

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'
Run Code Online (Sandbox Code Playgroud)

因此,*(InterceptionKeyStroke*)转换为指针,然后取消引用指针.