关于RECT初始化的好奇心......不是真正的问题...... [英] Curiosity about RECT initialization... Not really a problem...

查看:65
本文介绍了关于RECT初始化的好奇心......不是真正的问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在我的WinClass类中声明了一个WindowSize RECT作为私有变量。我试图在构造函数中使用块初始化,但是,它让我分别初始化每个成员所以我的问题是为什么这不起作用?

 WindowSize = {  0  0  300  300 }; 



这个有用:

 RECT WindowSize = { 0  0  300  300 }; 



就像我在标题中说的那样,对我来说更像是一种好奇心,所以如果你有时间和耐心向我解释,请允许我事先说谢谢 - 史蒂夫。

WinClass.h

< pre lang =c ++> private
RECT WindowSize;



WinClass。 cpp

 WinClass :: WinClass(HINSTANCE hInstance){
WindowSize = { 0 0 800 600 }; ...}



错误:

错误C2059:语法错误:'  {' 
错误C2143:语法错误:在'之前缺少' ; {'
错误C2143:语法错误:缺少' ;'' }'

解决方案

此代码在编译时声明了一个带有一些初始值的新变量,这很好,编译器从头开始创建变量。 />

 RECT WindowSize = { 0  0  300  300 }; 





此代码

 WindowSize = { 0  0  300  300 }; 



尝试将多个值分配给现有变量,在运行时,这是不允许的。在运行时,您必须单独分配类或结构的每个成员。


So I have a WindowSize RECT declared as a private variable in my WinClass, class. I tried to use block initialization in the constructor, but alas, it made me initialize each member separately so my question is why doesn't this work?

WindowSize = { 0, 0, 300, 300 };


This works:

RECT WindowSize = {0,0,300,300};


Like I said in the title it is more of a curiosity for me, so if you have the time and patience to explain it to me, allow me to say thanks in advance -- Steve.
WinClass.h

private:
	RECT WindowSize;


WinClass.cpp

WinClass::WinClass(HINSTANCE hInstance){
	WindowSize = { 0, 0, 800, 600 };...}


Errors:

error C2059: syntax error : '{'
error C2143: syntax error : missing ';' before '{'
error C2143: syntax error : missing ';' before '}'

解决方案

This code declares a new variable with some initial values at compile time, and that is fine, the compiler creates the variable from scratch.

RECT WindowSize = {0,0,300,300};



This code

WindowSize = { 0, 0, 300, 300 };


tries to assign multiple values to an existing variable, at run time, which is not allowed. At run time you must assign each member of the class or structure individually.


这篇关于关于RECT初始化的好奇心......不是真正的问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆