简体   繁体   English

Visual Studio 2010 c ++编译器问题

[英]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: 和截图:

VS2010错误

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: lst1lst2lst3 ... 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.

相关问题 使用visual C ++编译器(Visual Studio 2010)导致变量数组大小出错。如何规避这个问题? - Error with variable array size using the visual C++ compiler (Visual Studio 2010). How to circumvent this issue? C ++或Visual Studio 2010的问题 - Issue with C++ or Visual Studio 2010 Visual Studio 2010自动切换到C ++ / CLI编译器 - Visual studio 2010 automatically switched to C++/CLI compiler Visual Studio 2010 C ++编译器为类分配错误的大小 - Visual Studio 2010 C++ compiler allocating wrong size for class Visual Studio 2010中是否有编译器设置可确保编写可移植的C ++? - Are there compiler settings in Visual Studio 2010 to ensure the writing of portable C++? 使用Visual Studio 2010 C ++编译器和链接器,但未安装Visual Studio 2010 - Using Visual Studio 2010 C++ compiler and linker without Visual Studio 2010 having been installed 如何将Visual Studio 2010与Visual C ++ 2008编译器一起使用? - How can I use Visual Studio 2010 with the Visual C++ 2008 compiler? 我可以在Visual Studio 2008的C ++运行时库中使用Visual Studio 2010的C ++编译器吗? - Can I use Visual Studio 2010's C++ compiler with Visual Studio 2008's C++ Runtime Library? 如何强制MIDL编译器在Visual Studio 2010中使用“C ++模式”而不是“C模式”? - How to force MIDL compiler to use “C++ mode” instead of “C mode” in Visual Studio 2010? C++ Visual Studio 2010 C4717 编译器警告在代码的一部分中,但在另一部分中没有 - C++ Visual Studio 2010 C4717 compiler warning in one part of code but not in another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM