为什么我必须在这种情况下参考?

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;
}

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

回答

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

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


以上是为什么我必须在这种情况下参考?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>