English 中文(简体)
Can Someone Explain The Snippet (这里有这些困难吗?)
原标题:Can Someone Explain This Snippet (Why Are These Braces Here)?

我对这一过于简单化的问题表示歉意,但我似乎无法在一读书中列举这个例子:

void f5()
{
    int x;
    {
        int y;
    }
}

围绕<代码>int y的图书馆是什么? 你们能否在你们想要的地方bra? 如果是的话,那么你何时和为何会这样做,或者这只是一本书上的错误吗?

最佳回答

象这样的斜线表明,镜头中的代码现在范围不同。 如果你试图进入图书馆之外,你会遇到错误。

问题回答

它涉及范围变数问题,例如:

void f5()
{
    int x = 1;
    {
        int y = 3;
        y = y + x;          // works
        x = x + y;          // works
    }
    y = y + x;              // fails
    x = x + y;              // fails
}

它确定了范围。 变数Y无法在图书馆之外获得。

缩略语的范围是,变数x将可见于内容的范围,但不会出现在宽度范围之外。

图书馆界定范围。 在图书馆外,<代码>y将不予提供。

在从场外,内物体被拆除。 例如,你可以附上一门重要的布局,在那里建造一个锁的物体。 那么,你不必担心要打破僵局——通常或由于例外情况,在撤离范围时,通常会自动叫 des。

That looks like an error (not knowing the context)

Doing that you have boxed the value y inside those braces, and as such is NOT available outside it.

Of course, if they are trying to explain scope, that could be a valid 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?

热门标签