scope

Constants and Classes Declarations Across Multiple Source Files in C++

I am sure this problem is asked a lot but I can't seem to find anything relevant. I have multiple source files in a C++ project. In typical fashion, there are multiple header files with class and function declarations and associated source files with their definitions. The problem is that when I try to use one of my classes defined in an...

Variable Global Scope understanding questions

Hey, my question is actually one of understanding - I have a working solution, I just don't understand how it works. Okay, so - what I'm trying to do is adding a setTimeout in a loop, and passing a changing value through it. Example: for (i=0;i<11;i++) { setTimeout("alert(i)",1000); } If I understood correctly, this doesnt work...

How does the Javascript "this" operator deal with scopes?

Edit: I have to apologize, the problem I posted about actually does not exist in the code I posted, because I oversimplified it. I'll try to post something later. Deletion would also be ok, but there are too many answers at present, so I cannot do it myself. Edit2: Ok, here goes: Let, function F() { this.field = "value" ; v...

JqGrid: Trying to add a + button to the right of a "add" form field (using elmsuffix)

I can get the icon to show up, and it fires a simple alert if I place the javascript line in the href but I cannot attach a dialog object to the link id. I am using "elmsuffix" to get the html there: This works: {name:'name',index:'name',width:100, editable: true, formoptions:{elmsuffix: "<a id="companysearch" href="javascript:alert...

populate c++ maps content in a loop scope

I try to populate the content of a c++ map within a loop scope. #include <set> #include <map> map<int, set<int> > maps; for (int i=0; i<10; i++) { set<int> seti; // content: a set of integers seti.insert(i); seti.insert(...); maps.insert ( pair<int,set<int> >(i,seti) ); } The question is: does maps.insert copy the pa...

How do I access class variables from an event in Javascript?

I'm using the prototype javascript libraries. My code is below. I've created a class and in that class I have created an event listener for one of the class methods. In that method I need to access both the attributes of the form element that triggers the event and the class properties. Currently, the code understands $(this).getValue...

Scope in C#, what happens when there is a function call? Is the scope lost?

I have a object, namely "server" which loses it existence when the control of program is out of scope. So in general for any such objects, and memory of objects, when a function is called from within a scope, is the object lost? like void main void { if this and that { //scope do this call_func(); } }...

Yet another javascript function scope question

In this code, the ident and data variables are correct in the callback, but I don't know how to pass in the right i for each loop iteration. I've tried reading up on functions and tried like 10 things, but alas, I must seek the wisdom of the stack. function callback() { $(ident).html( data.fields[i].value ); $(ident).fadeTo('sl...

mutually referential classes yield "incomplete type" error

I have a situation in which A has a reference to a class C defined inside B, and C has an instance of class B. When I try to compile the code below, I get "field a has incomplete type". I assume this is because the compiler does not know how much memory it should allocate for an instance of A. class A; class B { public: class C { ...

Lexically-scoped ordering behavior

I have a class with two definitions of ordering. (In the real problem, one is a total order and one is a semiorder.) But it's nice to be able to use the comparison operators rather than always having to use an explicit comparison function or functor object. So I figured I'd provide some comparison operators like this: class C; names...

Authlogic, rails3_acts_as_paranoid and validates_uniqueness_of :login + default_scope(:conditions => {:active => true})

I want to be able to create multiple user accounts with the same login (because of the case a user deletes his account... and then sign up with the same login). I am using authlogic and rails3_acts_as_paranoid. But there is a problem: Authlogic validates the uniqueness of the login field - and IGNORES the default_scope(:conditions => {:...

Any way to reuse an identifier within a scope?

Normally using the same identifier like name of a variable for something like another variable within the same scope generates error by compiler, Is there any technique to actually indicate to compiler that in this scope up to this specific point this name has its own purpose and is used to refer to this variable but after this point the...

Syntax Error: identifier 'Edge' ?

At the consturctor Node = new Node[numberOfNodes]; and Edge = new Edge[numberOfEdges]; gives identifier error? what's the wrong with it ? typedef struct node { int id; int x; int y; } Node; typedef struct edge { int id; Node node1; Node node2; } Edge; class graph { private: int numberOfNodes; int numberOfEdges; int *Node; in...

Returning value from a function

const char *Greet(const char *c) { string name; if(c) name = c; if (name.empty()) return "Hello, Unknown"; return name.c_str(); } int _tmain(int argc, _TCHAR* argv[]) { cout << Greet(0) << '\t' << Greet("Hello, World") << endl; return 0; } I see 2 bugs with the above code. Returning c_str from...

Stack overflow in Prolog

I am trying to write Prolog code to determine whether the bound variable X is in the scope of the bound variable Y in a list. Lists may be nested and X is in the scope of Y if X and Y are members of the same list or if X is a member of a list that is a member of a list that is a member of a list...(nested indefinitely) that is in the sam...

Variable scope in multithreading, why my object reference is lost ?

Briefly under a single producer - single consumer scenario, I used a mutable object for synchronization and passing data and messages between producer and consumer. Shared buffer is a ConcurrentQueue of byte arrays. To implement a circular buffer and prevent heap fragmentation and frequent object swapping by GC I used a ConcurrentBag of ...

Why doesn't my Perl variable have the right value outside the if() block?

I have a hash, where the keys and values are from matches in a regular expression. I'm having difficulty extracting the values given the keys. In the interest of brevity and honing in on the problem, my first version of this post I attempted to strip down my program to only the relevant parts, but it wasn't enough, so here's more. Variab...

Object Expected error in IE7 - problem with function scope?

Hi - I'm having what I hope is a simple-to-fix issue. Basically, I've got one block of javascript containing the function, and then I'm trying to call it from another block of javascript (within a jQuery $(document).ready function). Whilst it works fine on Firefox, I get an 'Object Expected' error in IE7. It's probably something to do w...

ruby: how to load .rb file in the local context

How this simple task can be done in Ruby? I have some simple config file === config.rb config = { 'var' => 'val' } I want to load config file from some method, defined in main.rb file so that the local variables from config.rb became local vars of that method. Something like this: === main.rb Class App def loader load('co...

PHP closures and implicit global variable scope

Is there a way that one can implicitly declare top-level variables as global for use in closures? For example, if working with code such as this: $a = 0; //A TOP-LEVEL VARIABLE Alpha::create('myAlpha') ->bind(DataSingleton::getInstance() ->query('c') ) ->addBeta('myBeta', function($obj){ $obj->bind(DataSing...