Scope with Brackets in C++

后端 未结 5 1868
滥情空心
滥情空心 2020-12-01 17:50

Is there any case in which putting code within brackets to reduce its scope is something that I might want to do, or is this one of those cases in which you guys will tell m

5条回答
  •  醉酒成梦
    2020-12-01 18:37

    With all the things you can do in C++, adding a scope would really be the least of them. There is nothing wrong with the code you have, I do it sometimes (often in a case to ensure the locals are restricted to the case). Depending on the use you may like to think about refactoring the code into a separate function.

提交回复
热议问题