如何访问 class 成员在 class 中指向的地址?
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);
}
}
更多详情
这个函数是 class Input 的实现并且 class 有一个指向 sf 的私有变量::RectangleShape 在程序的 int main() 中。
我正在尝试访问 sf::RectangleShape 的实例,以便将对象在屏幕上向下移动。我不想创建一个全局变量 class 来完成这项工作。我只想能够访问该特定对象的方法。
您需要 指向成员 运算符的指针:
Input::playerOne->move(0.0, 1.0);
不需要显式范围解析Input::
,您可以重写为
playerOne->move(0.0, 1.0);
input.cpp 有错误的函数
void Input::isKeyPressed()
{
if ( sf::Keyboard::isKeyPressed ( sf::Keyboard::S ) )
{
// Here's The Error
*Input::playerOne.move(0.0 , 1.0);
}
}
更多详情
这个函数是 class Input 的实现并且 class 有一个指向 sf 的私有变量::RectangleShape 在程序的 int main() 中。
我正在尝试访问 sf::RectangleShape 的实例,以便将对象在屏幕上向下移动。我不想创建一个全局变量 class 来完成这项工作。我只想能够访问该特定对象的方法。
您需要 指向成员 运算符的指针:
Input::playerOne->move(0.0, 1.0);
不需要显式范围解析Input::
,您可以重写为
playerOne->move(0.0, 1.0);