scope

How to make a variable avaliable to multiple .cpp files using a class?

被刻印的时光 ゝ 提交于 2019-12-13 01:17:10
问题 This question has derived from this one. I have a working program which must be split into multiple parts. In this program is needed to use a variable (now it's a GTK+ one :P) many times in parts of the program that will end up in separated .cpp files. So, I made a simple example to understand how to make variables avaliable to the program parts. A modified version of the previous code would be: #include <iostream> using namespace std; int entero = 10; void function() { cout<<entero<<endl; /

Accessing Shadowed Variable in Self Executing Function

拥有回忆 提交于 2019-12-13 01:09:39
问题 In the following example, is there any way to get a reference to the someValue variable declared outside someFunction from within someFunction or is it completely obscured by the function's parameter of the same name. I appreciate that I could attach it to window and access it from within the function using this , but is there a way of accessing it in this situation? [Edit] To clarify. I understand that the parameter is shadowing the variable. Obviously changing the name of the parameter

Rails: both block arg and actual block given

自闭症网瘾萝莉.ら 提交于 2019-12-13 01:05:54
问题 I am trying to make an app in Rails 4. I have this code in my profiles show page, to show all the projects a user has created. <div class="row"> <div class="col-md-10 col-md-offset-1"> <% Project.all_current_for_creator(@creator).sort_by(&:created_at) do |project| %> <div class="row"> <div class="col-md-4"> <div class="indexdisplay"> <%= image_tag project.hero_image_url, width: '100%', height: '200px' if project.hero_image.present? %> </div> </div> <div class="col-md-8"> <div class="row">

scope through associations : joins and merge

自古美人都是妖i 提交于 2019-12-13 01:00:49
问题 I have three models : User , Product and Transaction . ( Transaction belongs_to both, and User has many Product and Product has many User , through Transaction ) In my Transaction model, I have a scope for current transactions : scope :current, -> { where 'transactions.start_date IS NOT NULL AND transactions.end_date IS NULL' } I want to be able to do that in the console, in order to retrieve all the products that have a current transaction : User.first.products.owned In the console, I can

cxf request scoped bean not working in unit test (soap)

对着背影说爱祢 提交于 2019-12-13 00:52:46
问题 CXF soap application, using following versions: springBootVersion = 1.2.3.RELEASE springVersion = '4.1.6.RELEASE' cxfVersion = '3.1.0' junitVersion = '4.12' I have a spring bean with a request scope: @Component @Scope( value=WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS ) public class RequestScopedClass which I fetch dynamically from ApplicationContext in my CXF endpoint implementation: @Component @WebService(endpointInterface = "ch.xyz.PaymentServiceInterface"

How to write a variable to the parents' parent scope in CMake?

安稳与你 提交于 2019-12-13 00:48:36
问题 I know that when I am in a function, I can set the variable in the calling scope by using: set(MYVAR 1 PARENT_SCOPE) What I want is to be able to set a variable in the grandparent scope (if it exists). I know that if I redefine my function as a macro, then set(MYVAR 1 PARENT_SCOPE) effectively does what I need. But unfortunately, I cannot do that for unrelated reasons. A solution would work for me as a walkaround for the problem in How to check if the variable is set in the parent scope, (as

Referencing own constructor in inner function

大兔子大兔子 提交于 2019-12-13 00:46:32
问题 Here's a toy example distilled from a complex class: public class MyClass { public function MyClass() { trace('Created'); } public static function makeObjectAsync(callback:Function):void { inner(); function inner():void { var object:MyClass = new MyClass(); // line 10 callback(object); } } } After calling the static function: MyClass.makeObjectAsync(function(object:Myclass):void { ... }) the following run-time exception occurs at line 10: TypeError: Error #1007: Instantiation attempted on a

How to access the variables after if-condition when the variable is defined inside the if-condition in python

无人久伴 提交于 2019-12-13 00:20:59
问题 I need to access variable from outside of if-condition when the variable is created inside the if-condition in python. The variable types which are inside if-condition are test is <type, str> and vn is <type, instance> . I have tried the below way but it has not worked for me. In the below code I need to access vn and test variables for DO in range(count) : atnnames = doc.getElementsByTagName("atnId")[DO] atn = atnnames.childNodes[0].nodeValue if atn == line[0]: vn = doc.getElementsByTagName(

How do I know when to use .bind() on a function in JS?

大城市里の小女人 提交于 2019-12-13 00:18:43
问题 (I'm aware of this question, but the answers don't quite tell me what I need to know.) I've come across cases where I need to use .bind() on a function in JavaScript in order to pass this or local/class variables to a function. However, I still don't really know when it's needed. What is the criteria for knowing when this or local/class variables will or will not be available in a function, exactly? How do you reason about this? For instance: When a new anonymous function() { } is created,

mongodb mapreduce scope - ReferenceError

空扰寡人 提交于 2019-12-13 00:12:41
问题 I'm trying to use an external object inside mongodb map/reduce functions. If the object has a variable which it should access, an error occurs. For example: var conn = new Mongo(); var db = conn.getDB("test"); var HelperClass = function() { var v = [1, 2, 3]; this.data = function() { return v; }; }; var helper = new HelperClass(); var map = function() { helper.data().forEach(function(value) { emit(value, 1); }); }; var reduce = function(key, values) { var count = 0; values.forEach(function