English 中文(简体)
为什么视觉演播室把警告称为“声势表达方式”? [复制]
原标题:Why Does Visual Studio Give the Warning "Relational Expression As Switch Expression"? [duplicate]

我有以下法典:

float x = 0.43;
float y = 1.56;
size_t largerValueIndex = 1;
size_t smallerValueIndex = 0;
switch (x > y) {
case 1:
    largerValueIndex = 0;
    smallerValueIndex = 1;
    break;
}

视力演播室发布警告“C4144: > :作为开关声明的关系表述”。

What I d like to know is why is the warning necessary? I was under the impression that most switch and if statements are comparisons between two values. Is this considered bad practice? And if so, why?

我的问题必须涉及作为开关表达方式所使用的价值,而不是那些情况。

最佳回答

虽然switch (-relational expression- ) 是法律,但通常不使用,因为只有两种价值观和if ( expression){......true Code...} 否则{......false Code......>更容易理解。

转换通常用于一种分类变数或表述,以便有效地列出预期值,而不是一个长期链条<代码>,如果......[......]

问题回答

虽然该守则是正确的,但switch通常用于具有两种以上可能结果的情景;只有两种可能结果的检验标准应为<>if/code>。

编辑们对此提出警告,因为意外使用<代码>switch<>/code>可能显示一种打字或逻辑错误。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签