c++ - 如何像我以前在 C++ 中做的那样在 swift 中做指针

标签 c++ swift pointers

因此,我能找到的有关执行此操作的文档非常少。我想念 c++ 的一个重要功能是能够做这样的事情(对于任何语法错误我很抱歉我在 c++ 中有点生疏

Int* Chosenint;
Int option1 = 1
Int option2 = 2
Int option3 = 3

if (the sun is up)
    Chosenint = &option1
else
    Chosenint = &option2

但是 swift 不识别“*”或“&”运算符。我想要做的就是拥有一个全局变量,该变量存储指向 SKSpriteNode 的指针,并且可以更改为不同的指针。 swift 似乎只有大型的 UnsafeMutablePointer 东西。那么,您将如何使用 skspritenodes 快速编写该 C++ 代码?

最佳答案

All I am trying to do is have a global variable that stores a pointer to a SKSpriteNode, and can change to a different one. All swift seems to have is the large UnsafeMutablePointer thing. So how would you do that c++ code in swift but with skspritenodes?

SKSpriteNode是一个类,即引用类型,所以你什么都不用做。你得到没有星号和符号的行为。

关于c++ - 如何像我以前在 C++ 中做的那样在 swift 中做指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32303041/

相关文章:

c++ - 如何使用函数指针声明 lambda(不带 auto)?

c++ - 在什么情况下为 Qt MinGW 或 MSVC 选择什么编译器?

Android NDK GCC 似乎是 clang - 它应该是这样吗?

c++ - 将 std::deque 的现有元素推到前面?

c++ - gcc 4.8 或更早版本是否存在关于正则表达式的问题?

ios - 单个选项卡栏项目根据条件呈现不同的 View Controller ?

swift - Apollo iOS 代码生成 : Nested use of a fragment in a mutation creates unexpected property types in Fragments struct

ios - 如果我在 swift 中添加 UITapGestureRecognizer,UIButton 单击事件不起作用

c - 用指针输入定义函数

c - 难以理解指针在 c 中的工作原理