scope

What does “using namespace” do exactly?

╄→гoц情女王★ 提交于 2021-02-16 05:48:05
问题 The following C++ test code does not link (gcc 4.9.2, binutils 2.25). The error is In function 'main': undefined reference to 'X::test' . 01: #include <string> 02: #include <iostream> 03: 04: namespace X 05: { 06: extern std::string test; 07: }; 08: 09: using namespace X; 10: std::string test = "Test"; 11: 12: int main() 13: { 14: std::cout << X::test << std::endl; 15: } Because of line 09, I was expecting line 10 to define the X::test variable declared on line 06. I believe that instead an

Variable not recognized in else statement in a bat file

*爱你&永不变心* 提交于 2021-02-11 17:14:49
问题 I have the follow code: ECHO OFF :LOOP set c= setlocal ENABLEDELAYEDEXPANSION tasklist | find /i "calc.exe" >nul 2>&1 IF %ERRORLEVEL% == 0 ( ECHO easymeetingOnCall is running taskkill /IM calc.exe /F set c=true Timeout /T 10 goto LOOP ) ELSE ( IF "!c!" == "true" ( ECHO l'applicazione easymeetingOnCall è spenta. Timeout /T 10 goto exitLoop ) ECHO easymeetingOnCall is not running Timeout /T 5 /Nobreak GOTO LOOP ) :exitLoop My problem is that the follow condition IF "!c!" == "true" Into the else

Variable not recognized in else statement in a bat file

一笑奈何 提交于 2021-02-11 17:11:32
问题 I have the follow code: ECHO OFF :LOOP set c= setlocal ENABLEDELAYEDEXPANSION tasklist | find /i "calc.exe" >nul 2>&1 IF %ERRORLEVEL% == 0 ( ECHO easymeetingOnCall is running taskkill /IM calc.exe /F set c=true Timeout /T 10 goto LOOP ) ELSE ( IF "!c!" == "true" ( ECHO l'applicazione easymeetingOnCall è spenta. Timeout /T 10 goto exitLoop ) ECHO easymeetingOnCall is not running Timeout /T 5 /Nobreak GOTO LOOP ) :exitLoop My problem is that the follow condition IF "!c!" == "true" Into the else

I want to take out the result from mysql's connection.query and save it in global scope chain in nodejs

非 Y 不嫁゛ 提交于 2021-02-11 13:02:14
问题 I tried bringing out result by storing in variable current product. But I cant use it outside the function, so my array returns empty var connection = mysql.createConnection({ host: config.config.mysql.opencart_local.host, user: config.config.mysql.opencart_local.user, password: config.config.mysql.opencart_local.password, database: config.config.mysql.opencart_local.database }) var query_current_products = 'select * from table;'; var current_products = []; connection.connect(function(err) {

Breaking lexical scope to prevent finding all references

℡╲_俬逩灬. 提交于 2021-02-11 12:28:55
问题 Apart from text-to-code methods, like eval / Function , or adding additional scripts, are there any more ways to shroud lexical scoping, which would invalidate a basic lexical search for an identifier's declaration, and all references? This is related to e.g. vs-code's "rename" (F2 by default), more precisely, implementing similar functionality. In other words, locally observing a snippet from a larger program, and renaming an identifier - not in a normal "best practice" situation, but where

Static variable shadowing global

为君一笑 提交于 2021-02-09 11:13:15
问题 I am trying to create an object using placement new (I know to use smart pointers, this is just to learn). My code is as follows: #include <vector> #include <iostream> #include <memory> using namespace std; // please excuse this // if you change like 19 to arr1 (or any other var name) instead of arr and line 40 to arr1 then it works struct A { int in = 999; A() {cout << "A ctor\n";} ~A() {cout << "A dtor\n";} }; char arr[sizeof(A)]; class B { public: static char arr[sizeof(A)]; const static A

Static variable shadowing global

纵饮孤独 提交于 2021-02-09 11:12:24
问题 I am trying to create an object using placement new (I know to use smart pointers, this is just to learn). My code is as follows: #include <vector> #include <iostream> #include <memory> using namespace std; // please excuse this // if you change like 19 to arr1 (or any other var name) instead of arr and line 40 to arr1 then it works struct A { int in = 999; A() {cout << "A ctor\n";} ~A() {cout << "A dtor\n";} }; char arr[sizeof(A)]; class B { public: static char arr[sizeof(A)]; const static A

Ruby - local variable gets modified when changing instance variable

半城伤御伤魂 提交于 2021-02-08 10:44:23
问题 temp gets @board.dup , and @board array is modified. However, temp gets modified as well! I have tried reading all the related documentations but still couldn't figure out an explanation. class Test def initialize @board = [[1,2],[3,4], [5,6]] end def modify temp = @board.dup #Also tried .clone print 'temp: ';p temp print '@board: ';p @board @board.each do |x| x << "x" end print "\ntemp: ";p temp print '@board: ';p @board end end x = Test.new x.modify Output: temp: [[1, 2], [3, 4], [5, 6]]

Ruby - local variable gets modified when changing instance variable

故事扮演 提交于 2021-02-08 10:43:16
问题 temp gets @board.dup , and @board array is modified. However, temp gets modified as well! I have tried reading all the related documentations but still couldn't figure out an explanation. class Test def initialize @board = [[1,2],[3,4], [5,6]] end def modify temp = @board.dup #Also tried .clone print 'temp: ';p temp print '@board: ';p @board @board.each do |x| x << "x" end print "\ntemp: ";p temp print '@board: ';p @board end end x = Test.new x.modify Output: temp: [[1, 2], [3, 4], [5, 6]]

JavaScript: Understanding let scope inside for loop [duplicate]

我只是一个虾纸丫 提交于 2021-02-08 09:52:40
问题 This question already has answers here : Explanation of `let` and block scoping with for loops (3 answers) Closed last year . Please consider snippet below- for(let i = 1; i <= 5; i++) { setTimeout(function(){ console.log(i); },100); } In this case, logs inside setTimeout will contain values of variable i as per each iteration of the for loop, i.e the logs will be as follow 1 2 3 4 5 For this, I have read explanations over the Internet like - let creates a variable declaration for each loop