Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;结构和构造_C++_Visual C++_Winapi_Structure - Fatal编程技术网

C++ c++;结构和构造

C++ c++;结构和构造,c++,visual-c++,winapi,structure,C++,Visual C++,Winapi,Structure,好的,所以我需要你的帮助 struct balls { balls() { SetTimer(hWnd, balls.BALL_ID, 1, null); } int Ex; int Ey; UINT_PTR BALL_ID; }; 结构球{ 球() { 设置计时器(hWnd,balls.BALL_ID,1,null); } int-Ex; INTEY; UINT_PTR BALL_ID

好的,所以我需要你的帮助

struct balls { balls() { SetTimer(hWnd, balls.BALL_ID, 1, null); } int Ex; int Ey; UINT_PTR BALL_ID; }; 结构球{ 球() { 设置计时器(hWnd,balls.BALL_ID,1,null); } int-Ex; INTEY; UINT_PTR BALL_ID; }; 当我设置计时器时,我对balls.BALL\u ID有问题。编译器认为balls的结构类似于balls。我想让ball具有结构的值。像这样

balls() { SetTimer(hWnd, balls.BALL_ID, 1, null); } int Ex; int Ey; UINT_PTR BALL_ID; }; balls something; 球() { 设置计时器(hWnd,balls.BALL_ID,1,null); } int-Ex; INTEY; UINT_PTR BALL_ID; }; 扔东西; 现在它使用something.BALL\u ID而不是balls.BALL\u ID创建结构。 在balls()中,wat do将balls()更改为某物()。
知道如何将balls.BALL\u ID更改为stuctureName.BALL\u ID吗?

balls.BALL\u ID要求“BALL”是一个对象表达式。这里的“球”是一门课。因此,代码的格式不正确

$5.2.5/2规定:“对于第一个选项(dot),第一个表达式(对象表达式)的类型应为“类对象”(完整类型)。”

所以,你的电话可能是

SetTimer(hWnd, BALL_ID, 1, null);

另外,在使用构造函数之前,请初始化构造函数中的所有类成员。

BALL\u ID
balls
结构的成员,因此当您想在成员函数中使用它时,不需要在它前面加上实例的名称。 因此,只需初始化
BALL\u 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 );

这些被称为“构造函数”而不是“构造函数”。请注意,hWnd也必须是可访问的。@安东尼:没错,我稍微假设hWnd是一个全局变量。。。(刚刚意识到我写的是
null
,而不是
null
)。