[英]Visual Studio 2010 c++ compiler issue
I have the following very strange situation... my Visual Studio compiler 2010 does not like the following piece of code: 我有以下非常奇怪的情况...我的Visual Studio编译器2010不喜欢以下代码:
QStringList lst2 = instantiatedTableInstances.split(strComma, skipper);
for(int i=0; i<lst2.size(); i++)
{
TableInstance* tabInst= v->getTableInstance(lst2.at(i));
result->addInstantiatedTableInstance(tabInst);
}
it gives me: 它给了我:
..\src\DeserializationFactory.cpp(1196) : error C2143: syntax error : missing ';' before 'constant'
..\src\DeserializationFactory.cpp(1196) : error C2440: '=' : cannot convert from 'QStringList' to 'int'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
..\src\DeserializationFactory.cpp(1198) : error C2228: left of '.size' must have class/struct/union
type is 'int'
..\src\DeserializationFactory.cpp(1200) : error C2228: left of '.at' must have class/struct/union
type is 'int'
and a screenshot: 和截图:
BUT if I rename the variable to lst
instead of lst2
everything compiles... 但如果我将变量重命名为
lst
而不是lst2
所有内容都会编译...
Is this a funny bug in Visual Studio 2010 (because GCC does not care about it) or there is a more hidden reason for this? 这是Visual Studio 2010中的一个有趣的错误(因为GCC不关心它)或者有更隐蔽的原因吗?
These kind of errors are usually the result of an unexpected macro with the same name of your variable. 这些错误通常是与变量名称相同的意外宏的结果。 A bit of google will find you this line in the Windows SDK header
Dlgs.h
: 有点google会在Windows SDK标头
Dlgs.h
找到这一行:
#define lst2 0x0461
That's what I call name pollution ! 这就是我所说的名字污染 !
My guess is that MS people thought that using a different ID for the controls of each dialog what hard to maintain, and so they though of giving the lists of any dialog the same IDs: lst1
, lst2
, lst3
... lst16
. 我的猜测是MS人员认为使用不同的ID来控制每个对话框难以维护的内容,因此他们给出了任何对话框的列表相同的ID:
lst1
, lst2
, lst3
... lst16
。 And the same with any other type of control. 与任何其他类型的控制相同。 But for some reason the idea didn't catch and the
Dlgs.h
header was forgotten. 但由于某种原因,这个想法没有抓住,
Dlgs.h
标题被遗忘了。
Now, the weird thing is that this header is included by default in your VC++ project and not in your GCC compilation. 现在,奇怪的是,此标头默认包含在VC ++项目中,而不包含在GCC编译中。 Maybe the environment is not the same.
也许环境不一样。
looks like you have already had a variable called lst, which has a type of int. 看起来你已经有了一个名为lst的变量,它的类型为int。 yes, i agree it looks like a bug of the compiler, since you are in a new variable space with if(secondStep){} wrapped.
是的,我同意它看起来像编译器的一个错误,因为你在if(secondStep){}包装的新变量空间中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.