scope

Is there a way to declare that a function should use the scope of the caller?

一笑奈何 提交于 2020-08-26 13:47:27
问题 is there a feautre similar to C macros which lets you reuse code in an inline manner, without creating a seperate scope for that piece of code? for example: a=3 def foo(): a=4 foo() print a will print 3, however i want it to print 4. i am aware of solutions involving objects like classes or a global dict, however i'm looking for a more primitive solution (like a function decorator for example) that would simply let me make changes inside the scope of the caller instead. thank you very much

while statement with initializer

允我心安 提交于 2020-08-24 10:26:04
问题 C++17 has selection statements with initializer status_code foo() { if (status_code c = bar(); c != SUCCESS) { return c; } // ... } I'd like to write a while -loop and a variable with a scope limited to the loop and initialized only once before the first iteration. // fake example, doesn't compile, is doable in many ways while (bool keep_trying = foo(); keep_trying) { // do stuff if (something) keep_trying = false; } Is there anything for this in C++17 or maybe coming in C++2a? 回答1: P0305R1,

When are VBA Variables Instantiated

回眸只為那壹抹淺笑 提交于 2020-08-24 10:23:24
问题 I'm hesitant to ask, but there's no documentation that I can find for VBA . Relevant (but I don't think a dupe): C++ When are global variables created? In Java, should variables be declared at the top of a function, or as they're needed? C++ Declare variables at top of function or in separate scopes? and the most likely relevant When are a module's variables in VB.NET instantiated? I also took a look at C# on programmers.SE. I think I'm using the word "Instantiate" right, but please correct