scope

Assigning value passed by reference to a member variable (in C++)

送分小仙女□ 提交于 2019-12-07 12:24:24
问题 I am trying to wrap my head about scope in C++. Please consider the following: class C { int i_; public: C() { i_ = 0;} C(int i) { i_ = i; } C(const C &c) { i_ = c.i_; cout << "C is being copied: " << i_ << endl; } int getI() { return i_; } ~C() {cout << "dstr: " << i_ << endl;} }; class D { C c_; public: void setC(C &c) { c_ = c; } int getC_I() { return c_.getI(); } }; void Test(D &d) { C c(1); d.setC(c); //here c is going out of scope, surely it will be destroyed now? } int main() { D d;

MAVEN Scope属性说明

馋奶兔 提交于 2019-12-07 12:13:44
在Maven的依赖管理中,经常会用到依赖的scope设置。这里整理下各种scope的使用场景和说明,以及在使用中的实践心得。 scope的使用场景和说明 1.compile 编译范围,默认scope,在工程环境的classpath(编译环境)和打包(如果是WAR包,会包含在WAR包中)时候都有效。 2.provided 容器或JDK已提供范围,表示该依赖包已经由目标容器(如tomcat)和JDK提供,只在编译的classpath中加载和使用,打包的时候不会包含在目标包中。最常见的是j2ee规范相关的servlet-api和jsp-api等jar包,一般由servlet容器提供,无需在打包到war包中,如果不配置为provided,把这些包打包到工程war包中,在tomcat6以上版本会出现冲突无法正常运行程序(版本不符的情况)。 3.runtime 一般是运行和测试环境使用,编译时候不用加入classpath,打包时候会打包到目标包中。一般是通过动态加载或接口反射加载的情况比较多。也就是说程序只使用了接口,具体的时候可能有多个,运行时通过配置文件或jar包扫描动态加载的情况。典型的包括:JDBC驱动等。 4.test 测试范围,一般是单元测试场景使用,在编译环境加入classpath,但打包时不会加入,如junit等。 5.system 系统范围,与provided类似

Scope based variable shadowing in JavaScript

扶醉桌前 提交于 2019-12-07 12:03:13
问题 I'm having difficulty understanding variable shadowing in JavaScript based on scopes. Consider this small code fragment: var k = { prop1: 'test', prop2: 'anotherTest' } for(var k = 0; k < 10; k++) { console.log(k); } //prints number console.log(typeof k); //prints 10 console.log(k); //undefined console.log(k.prop1); This is fine, because owing to the immediate function scope, the loop counter variable k shadows the json variable k we declated earlier. Hence the json variable k becomes

using lm(my_formula) inside [.data.table's j

。_饼干妹妹 提交于 2019-12-07 10:36:32
问题 I have gotten in the habit of accessing data.table columns in j even when I do not need to: require(data.table) set.seed(1); n = 10 DT <- data.table(x=rnorm(n),y=rnorm(n)) frm <- formula(x~y) DT[,lm(x~y)] # 1 works DT[,lm(frm)] # 2 fails lm(frm,data=DT) # 3 what I'll do instead I expected # 2 to work, since lm should search for variables in DT and then in the global environment... Is there an elegant way to get something like # 2 to work? In this case, I'm using lm , which takes a "data"

Global variables for class library in matlab

断了今生、忘了曾经 提交于 2019-12-07 10:04:11
问题 I have several matlab classes declared. How could I declare constants which are seen in all classes? For instance : these constants can be physical constants which are used in methods of all classes. The first thing coming to mind is using global variables. Is there any better way? It will be nice to declare these constants in a separate file. 回答1: A class containing the constants is a nice clean way to do this. See the article in Matlab documentation: http://www.mathworks.com/help/matlab

Mule expression variable scope

ⅰ亾dé卋堺 提交于 2019-12-07 09:23:50
问题 What is the scope of variables in Mule expression components, and how does that relate to flow variables? I had a flow with a set-variable and was surprised to see that the value was being overwritten by an assignment in an expression-component . For example, <flow name="HelloWorldFlow1" doc:name="HelloWorldFlow1"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="9999" doc:name="HTTP" doc:description="This endpoint receives an HTTP message." path="helloworld"/

Curious JavaScript performance dependent on variable scope

家住魔仙堡 提交于 2019-12-07 09:04:58
问题 When testing the performance of one JavaScript project, I noticed a very peculiar behavior - JavaScript member access performance seems to be heavily influenced by the scope they are in. I wrote a few performance tests, and the results were different by multiple orders of magnitude . I tested on Windows 10 64-bit, using these browsers: Google Chrome, version 49.0.2623.75 m - uses the V8 JavaScript engine Mozilla Firefox, version 44.0.2 - uses the SpiderMonkey JavaScript engine Microsoft Edge,

Rails I18n translations scoping

早过忘川 提交于 2019-12-07 09:03:30
问题 Writing a fully translated app can become tedious. Is there a way to set a default translation scope for the current context ? Example : I am writing inside a partial _deadlines.html.erb in the show.html.erb action of my ProjectsController Now because I am trying to be a good programmer, I am scoping all my translations. I would like to produce the following tree projects: deadlines: now: "Hurry the deadline is today !" .... How can I make it less tedious than writing each time the full scope

TclOO Variable Scope with Inheritance/superclass

 ̄綄美尐妖づ 提交于 2019-12-07 08:46:27
I stumbled over the variable scope when inheriting a class with TclOO. The member variable nCrumbs below is not visible to the inherited class without repeating the declaration. Is there a way to avoid replicating all the variable declarations from the superclass? (I read through all the OO documentation, specifically oo::define and oo::object, also the non-exported stuff, googled for it. There are so many concepts to get around various things, I got lost. I am looking for something that keeps the inherited class as simple as possible. The superclass may have any fancy complicated code in it,

What is 'this' before an object is instantiated in js?

核能气质少年 提交于 2019-12-07 07:28:48
问题 I don't understand the following: var x = function() { this.foo="foo"; return function() { this.bar = "bar"; return foo+bar; }; }(); // returns inner alert(x()); // 'foobar', so both 'this' variables are set alert(x.bar); // undefined - but wasn't it used correctly? alert(new x().bar); // ok, works My assumption was that a default 'this' scope/variable-map is generated and used the first time, and then when 'new' is called, a new object (function?) with a new 'this' is sent through and