T
T
totsamiyya2019-02-27 10:56:39
C++ / C#
totsamiyya, 2019-02-27 10:56:39

Why put curly braces after a method call?

For example, there is a class MyClass, it has a method int myMethod.
When called from another method of another class, the following construction is used:

MyClass::myMethod();
{
    ...
    различные операции
    ...
}

Or, for example, the situation when they put curly braces after initializing a variable:
int var = 0;
{
    ...
}

I met such constructions in different examples and I don’t really understand how this works.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ivan Bogachev, 2019-02-27
@totsamiyya

Curly braces create a new block with its own scope (this has nothing to do with the last expression):

int A = 0;

{
    int A = 1;
    int B = 1;
    std::cout << A << "\n"; // 1
    std::cout << B << "\n"; // 1
}
  
std::cout << A << "\n"; // 0
//std::cout << B << "\n"; // <-- error: B was not declared in this scope

G
GreatRash, 2019-02-27
@GreatRash

I am a complete zero in the pros, so I can only assume that this is somehow related to the scope of the variables. For example, some variables are not available from outside such a block. Or, for example, inside the block, you can do whatever you want with the variable var, but outside it will still be equal to zero.
Well, at least that would make sense.

S
Sergey, 2016-09-29
@void01

position:absolute; top:0; bottom:0;
if the screen height is not the page height but the screen height i.e. viewport, then height:100vh;
PS and in order for the height to be considered 100%, you also need to set the parent of the parent, and so on until we reach the top of the DOM or stumble upon an element with a height not in percent, from which we can start counting

A
Albert Kazan, 2016-09-29
@Farrien

Try
height: 100vh

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question