gpt4 book ai didi

C++ 结构和构造

转载 作者:行者123 更新时间:2023-11-28 08:27:20 25 4
gpt4 key购买 nike

好的,所以我需要有关此结构的帮助

struct balls {         balls()         {                SetTimer(hWnd, balls.BALL_ID, 1, null);         }    int Ex;    int Ey;    UINT_PTR BALL_ID;};

好吧,当我设置计时器时,我遇到了 balls.BALL_ID 的问题。编译器认为 balls 的结构类似于 balls 之类的东西。好吧,我希望球具有结构的值(value)。像这样

         balls()         {                SetTimer(hWnd, balls.BALL_ID, 1, null);         }    int Ex;    int Ey;    UINT_PTR BALL_ID;};balls something;

现在它使用 something.BALL_ID 而不是 balls.BALL_ID 创建结构。在 balls() 中,它所做的将 balls() 更改为 something()。知道如何将 balls.BALL_ID 更改为 stuctureName.BALL_ID 吗?

最佳答案

BALL_IDballs 结构的成员,所以当你想在成员函数中使用它时,你不需要在它前面加上实例名称前缀.所以只需初始化 BALL_ID 然后使用它:

struct balls {
balls( UINT_PTR id ) : BALL_ID( id ), Ex( 0 ), Ey( 0 )
{
SetTimer(hWnd, BALL_ID, 1, NULL);
}
int Ex;
int Ey;
UINT_PTR BALL_ID;
};

balls something( IDT_TIMER1 );

关于C++ 结构和构造,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3499899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com