scope

What is POI and what does it mean?

你说的曾经没有我的故事 提交于 2019-12-29 08:35:08
问题 What is POI? I have seen this term being used several times in context of C++ Templates. What does it mean? 回答1: POI means Point Of Instantiation. From C++ Templates : The Complete Guide 10.3.2 Points of Instantiation A point of instantiation (POI) is created when a code construct refers to a template specialization in such a way that the definition of the corresponding template needs to be instantiated to create that specialization. The POI is a point in the source where the substituted

How to register a service worker's scope one directory above where the service_worker.js is located

家住魔仙堡 提交于 2019-12-29 08:29:07
问题 MY directories are as follows. public_html/ sw/ The "sw/" is where I want to put all service workers, but then have those service workers with a scope to all the files in "public_html/". JS <script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('sw/notifications.js', { scope: '../sw/' }).then(function(reg) { // registration worked console.log('Registration succeeded. Scope is ' + reg.scope); }).catch(function(error) { // registration failed console.log('Registration

Java variable scope

落花浮王杯 提交于 2019-12-29 08:23:35
问题 when a variable is initialize both in local scope as well as global scope how can we use global scope without using this keyword in the same class? 回答1: class MyClass{ int i;//1 public void myMethod(){ i = 10;//referring to 1 } public void myMethod(int i){//2 i = 10;//referring to 2 this.i = 10 //refering to 1 } } Also See : Shadowing Declarations what-is-variable-shadowing-used-for-in-a-java-class 回答2: If you do not use this it will always be the local variable. 回答3: It is impossible without

Variable-length array in file scope?

假如想象 提交于 2019-12-29 08:16:49
问题 I have this code for example. #include <stdlib.h> #include <stdio.h> #define array_size 3 typedef struct { int array[array_size]; } TEST; void printout(TEST *p, int element) { printf("element: %i\n", p->array[element]); } int main(void) { TEST *p; p = malloc(sizeof(TEST)); p->array[0] = 5; printout(p, 0); return 0; } But I'd like to assign "array_size" based on user input. If I try to do so, the compiler says "variably modified ‘array_size’ at file scope" . So, am I right that the only way to

Lambda capture problem with iterators?

落花浮王杯 提交于 2019-12-29 08:10:10
问题 Apologies if this question has been asked already, but suppose we have this code (I've run it with Mono 2.10.2 and compiled with gmcs 2.10.2.0): using System; public class App { public static void Main(string[] args) { Func<string> f = null; var strs = new string[]{ "foo", "bar", "zar" }; foreach (var str in strs) { if ("foo".Equals(str)) f = () => str; } Console.WriteLine(f()); // [1]: Prints 'zar' foreach (var str in strs) { var localStr = str; if ("foo".Equals(str)) f = () => localStr; }

NameError using execfile in python

萝らか妹 提交于 2019-12-29 07:08:30
问题 My application has a button to execute a python script dynamically using execfile . If I define a function inside the script (eg. spam() ) and try to use that function inside another function (eg. eggs() ), I get this error: NameError: global name 'spam' is not defined What is the correct way to call the spam() function from within eggs() ? #mainprogram.py class mainprogram(): def runme(self): execfile("myscript.py") >>> this = mainprogram() >>> this.runme() # myscript.py def spam(): print

Usage of local variables

心不动则不痛 提交于 2019-12-29 06:49:09
问题 Problem: How to define local variables within a scope in a r-code. Example: In C++ the following example defines a scope, and variables declared within the scope are undefined in outside code. { vector V1 = getVector(1); vector V1(= getVector(2); double P = inner_product(V1, V2); print(P); } // the variable V1, V2, P are undefined here! Note: This code is only to illustrate the idea. This practice has the advantages of: Keeping the global namespace clean; simplifying code; removing

How to access class-scope variables without self?

落花浮王杯 提交于 2019-12-29 06:44:43
问题 So I have a class, which I'm using as a local namespace. I have some static functions in the class, but they can't access the class scope variables. Why is this? class Foo: foo_string = "I am a foo" @staticmethod def foo(): print foo_string >>> Foo.foo() [Stack Trace] NameError: global name 'foo_string' is not defined Any thoughts? 回答1: Python doesn't let class variables fall into scope this way, there are two ways to do this, the first is to use a class method: @classmethod def foo(cls):

Lexical scoping vs dynamic scoping

[亡魂溺海] 提交于 2019-12-29 06:25:00
问题 So I have this problem where I have to figure out the output using two different scoping rules. I know the output using lexical scoping is a=3 and b=1 , but I am having hard time figure out the output using dynamic scoping. Note:the code example that follows uses C syntax, but let's just treat it as pseudo-code. int a,b; int p() { int a, p; a = 0; b = 1; p = 2; return p; } void print() { printf("%d\n%d\n",a,b); } void q () { int b; a = 3; b = 4; print(); } main() { a = p(); q(); } Here is

Does 'let' override a global declaration and throws a ReferenceError?

孤者浪人 提交于 2019-12-29 06:14:28
问题 I was going through the Difference between var and let documentation example and was testing that when an undeclared variable is invoked, the global scope automatically provides a declaration for it (that's why the following snippet does not throw an error in any of the variables): x = 3; console.log(x); (function() { y=x+39; })() console.log(y); However, when one variable is declared with let after the assignment in the same global scope: x=3; let x = 42; console.log(x); One of the following