c++ - 在 C++ 中,这个结构是什么意思 "InterceptionKeyStroke &kstroke = * (InterceptionKeyStroke *) &stroke"?

标签 c++ pointers

我是C++新手,不懂这个构造。

InterceptionKeyStroke &kstroke = * (InterceptionKeyStroke *) &stroke

我知道 & = 指针。但这意味着什么?

* (InterceptionKeyStroke *)

最佳答案

分解:

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'

所以 *(InterceptionKeyStroke*) 正在转换为一个指针,然后取消引用该指针。

关于c++ - 在 C++ 中,这个结构是什么意思 "InterceptionKeyStroke &kstroke = * (InterceptionKeyStroke *) &stroke"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49464597/

相关文章:

c++ - 非常简单的 C++ 文本冒险的代码结构

c++ - C 多行宏问题 : why not use if(1){. ..} 而不是多行宏定义中的 do{...}while(0)

c++ - 'B::operator A' 使用未定义类 'A'

c - 在 C 中打印一个 int

c - 为什么使用不同的指针类型?

C++ getline 和 if/else if 语句没有按我的预期工作

c++ - Shogun 无法编译。这些是幕府将军的 bug 吗?

c++ - 如何在嵌入式系统上创建指向寄存器的 constexpr 指针

c++ - 如果不在同一范围内,则无法打开 SFML 2 窗口

c++ - WM_COMMAND 未传递到主窗口