出于某种原因,我似乎无法做到这一点 好的,我有 2 个对象
class score
{
public:
int scored(int amount);
private:
int currentscore;
}
int score::scored(int amount)
{
currentscore += amount;
return 0;
}
class collisions
{
public:
int lasers();
}
// ok heres my issue
int collisions::lasers()
{
// some code here for detection
// I need to somehow call score.scored(100);
score.scored(100); // not working
score::scored(100); // not working
// how do i do that?
}
collisions collisions;
score score;
int main()
{
while (true)
{
// main loop code here..
}
return 0;
}
最佳答案
这是你的问题:
collisions collisions;
score score;
你不应该声明一个与其类型同名的变量。将类型设为大写,一切都应该适合您。也不要忘记将这两个变量的定义移到它们所使用的函数之上。
关于c++ - 在不同的对象函数中调用对象函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3807826/