c++ - CreatePolygonRgn 和 const POINT *

标签 c++ c winapi gdi

我只给你关于我的问题的台词。我不知道为什么这不能编译:

POINT ptVertex[5];

ptVertex[0].x = 180;
ptVertex[0].y = 80;
ptVertex[1].x = 100;
ptVertex[1].y = 160;
ptVertex[2].x = 120;
ptVertex[2].y = 260;
ptVertex[3].x = 240;
ptVertex[3].y = 260;
ptVertex[4].x = 260;
ptVertex[4].y = 160;

CreatePolygonRgn( &ptVertex, 5, ALTERNATE )

我在 DevC++ TDM GCC 64 位上编译,错误是:

cannot convert 'POINT ()[5] {aka tagPOINT ()[5]}' to 'const POINT* {aka const tagPOINT*}' for argument '1' to 'HRGN__* CreatePolygonRgn(const POINT*, int, int)'

如果有人能发现我的错误。谢谢。

最佳答案

CreatePolygonRgn() 需要指向数组中第一个 POINT 的指针,以及数组中的项数。但是您向它传递了一个指向数组本身的指针,而不是它的第一个元素。您可以:

  1. 在应用 & 运算符之前指向数组第一个元素的索引:

    CreatePolygonRgn( &ptVertex[0], 5, ALTERNATE )
    
  2. 只需完全删除 & 运算符,因为静态数组可以退化为指向其第一个元素的指针:

    CreatePolygonRgn( ptVertex, 5, ALTERNATE )
    

关于c++ - CreatePolygonRgn 和 const POINT *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38000598/

相关文章:

c++ - 在一个简单的例子中解释并行代码执行和进一步的性能提升

c++ - 如何将纯文本转换为ODF?

c - C语言的设备通知程序

c++ - 陷阱 WM_SETFOCUS 消息

c++ - unicode 或任何其他编码数据如何存储在内存中? (win32)

c++ - 为什么 `equal` 在 C++ 中适用于 const char*?

c++ - 如何维护 V8 上下文以供将来使用?

c++ - 我可以使用 std::optional 进行错误处理吗?

c - f(x) := if x == 0 then 0 else (x * log(x)) 的无分支实现

c - 在堆栈中查找最小值,时间复杂度为 O(1)