首页 > 解决方案 > 为什么我必须在这种情况下参考?

问题描述

int main(){

while(true){

    char input = getchar();
    int x, y;
    POINT xypos;

    if (input == 'S' || input == 's'){

        std::cout <<"enter new position" << std::endl;
        std::cin >> x >> y;
        SetCursorPos(x, y);

    } else if (input == 'g' || input == 'G'){

        GetCursorPos(&xypos);
        std::cout << "X: " << xypos.x << "Y " << xypos.y << std::endl;
    }
}


    return 0;
}

有人可以解释一下为什么GetCursorPos它必须在参数中引用 xypos 对象吗?为什么不能直接使用呢?谢谢

标签: c++

解决方案


您可能的意思是为什么GetCursorPos(来自 WinAPI)不只是返回位置而不是获取指针并填充它?

这就是 WinAPI 的工作方式,几乎所有函数都返回BOOL以指示成功或失败,并获取它们通过指针填充的信息。


推荐阅读