如何访问类成员在类中指向的地址
How do I access the address that a member of a class is pointing to while within the class?
input.cpp 有错误的函数
void Input::isKeyPressed()
{
if ( sf::Keyboard::isKeyPressed ( sf::Keyboard::S ) )
{
// Here's The Error
*Input::playerOne.move(0.0 , 1.0);
}
}
更多详情
此函数是类 Input 的实现,该类有一个私有变量,用于指向程序的 int main() 中的 sf::RectangleShape 的指针。
我正在尝试访问 sf::RectangleShape 的实例化,以便在屏幕上向下移动对象。我不想创建一个全局变量类只是为了完成这项工作。我只是希望能够访问该特定对象的方法。
您需要指向成员运算符的指针:
Input::playerOne->move(0.0, 1.0);
显式范围解析Input::
不是必需的,可以重写为
playerOne->move(0.0, 1.0);
相关文章:
- C++:用户定义的类,以成员字段作为地址
- 为什么成员函数地址离自由函数这么远?
- Assimp 库错误:获取打包成员的地址
- C++ - 非静态 void* 成员,指向具有相同地址但不同值的不同对象的另一个非静态成员
- 在指向现有内存地址的 hpp 文件中声明成员函数的最佳方法
- C++多态性:有没有办法找到对象成员函数的地址?
- 如何获取结构体成员的地址
- 使用成员的地址初始化基类是否合法?
- C++:获取包含成员子对象的完整对象的地址
- 从对象及其成员的地址获取指向成员的指针
- 获取未初始化对象成员的地址是否定义良好?
- 指向未由对象地址初始化的对象的指针如何将值分配给类的数据成员
- 为什么有一个额外的 & 将非静态成员函数的地址传递给 C++ 中的线程?
- 类成员地址与类指针值相同
- 使用指向结构变量成员的指针访问该结构的成员的地址
- 类成员在构造函数(线程)之后更改地址
- 使用来自 Dll 的偏移地址调用成员函数
- 不太明白 & 运算符的地址在这个结构中做什么,以及它如何能够访问其他成员变量
- C 17标准是否保证工会的地址与其成员的地址相同
- 获取类成员功能的地址并从指针调用