Search Results

Search found 3148 results on 126 pages for 'angularjs scope'.

Page 25/126 | < Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >

  • Variable not accessible within an if statment

    - by Chris
    I have a variable which holds a score for a game. My variable is accessible and correct outside of an if statement but not inside as shown below score is declared at the top of the main.cpp and calculated in the display function which also contains the code below cout << score << endl; //works if(!justFinished){ cout << score << endl; // doesn't work prints a large negative number endTime = time(NULL); ifstream highscoreFile; highscoreFile.open("highscores.txt"); if(highscoreFile.good()){ highscoreFile.close(); }else{ std::ofstream outfile ("highscores.txt"); cout << score << endl; outfile << score << std::endl; outfile.close(); } justFinished = true; } cout << score << endl;//works

    Read the article

  • C++ Why am I unable to use an enum declared globally outside of the class it was declared in?

    - by VGambit
    Right now, my project has two classes and a main. Since the two classes inherit from each other, they are both using forward declarations. In the first object, right underneath the #include statement, I initialize two enums, before the class definition. I can use both enums just fine inside that class. However, if I try to use those enums in the other class, which inherits from the first one, I get an error saying the enum has not been declared. If I try to redefine the enum in the second class, I get a redefinition error. I have even tried using a trick I just read about, and putting each enum in its own namespace; that didn't change anything.

    Read the article

  • Where to store frequently used functions in a OOP correct way

    - by Stefan Kuijers
    I'm working on a project which I want to build up OO. Now I came with a function that checks or a value is valid. private function valid(value:*, acceptedValues:Array):Boolean { for(var i:uint = 0; i < acceptedValues.length; i++) { if (value == acceptedValues[i]) { return true; } } return false; } As you can see, the function is very general and will be accessed across different classes. Now my question is; where do I store it in a OO correct way? Thanks in advance!

    Read the article

  • When I overload the assignment operator for my simple class array, I get the wrong answer I espect

    - by user299648
    //output is "01234 00000" but the output should be or what I want it to be is // "01234 01234" because of the assignment overloaded operator #include <iostream> using namespace std; class IntArray { public: IntArray() : size(10), used(0) { a= new int[10]; } IntArray(int s) : size(s), used(0) { a= new int[s]; } int& operator[]( int index ); IntArray& operator =( const IntArray& rightside ); ~IntArray() { delete [] a; } private: int *a; int size; int used;//for array position }; int main() { IntArray copy; if( 2>1) { IntArray arr(5); for( int k=0; k<5; k++) arr[k]=k; copy = arr; for( int j=0; j<5; j++) cout<<arr[j]; } cout<<" "; for( int j=0; j<5; j++) cout<<copy[j]; return 0; } int& IntArray::operator[]( int index ) { if( index >= size ) cout<<"ilegal index in IntArray"<<endl; return a[index]; } IntArray& IntArray::operator =( const IntArray& rightside ) { if( size != rightside.size )//also checks if on both side same object { delete [] a; a= new int[rightside.size]; } size=rightside.size; used=rightside.used; for( int i = 0; i < used; i++ ) a[i]=rightside.a[i]; return *this; }

    Read the article

  • Declare Locally or Globally in Delphi?

    - by lkessler
    I have a procedure my program calls tens of thousands of times that uses a generic structure like this: procedure PrintIndiEntry(JumpID: string); type TPeopleIncluded = record IndiPtr: pointer; Relationship: string; end; var PeopleIncluded: TList<TPeopleIncluded>; PI: TPeopleIncluded; begin { PrintIndiEntry } PeopleIncluded := TList<TPeopleIncluded>.Create; { A loop here that determines a small number (up to 100) people to process } while ... do begin PI.IndiPtr := ...; PI.Relationship := ...; PeopleIncluded.Add(PI); end; DoSomeProcess(PeopleIncluded); PeopleIncluded.Clear; PeopleIncluded.Free; end { PrintIndiEntry } Alternatively, I can declare PeopleIncluded globally rather than locally as follows: unit process; interface type TPeopleIncluded = record IndiPtr: pointer; Relationship: string; end; var PeopleIncluded: TList<TPeopleIncluded>; PI: TPeopleIncluded; procedure PrintIndiEntry(JumpID: string); begin { PrintIndiEntry } { A loop here that determines a small number (up to 100) people to process } while ... do begin PI.IndiPtr := ...; PI.Relationship := ...; PeopleIncluded.Add(PI); end; DoSomeProcess(PeopleIncluded); PeopleIncluded.Clear; end { PrintIndiEntry } procedure InitializeProcessing; begin PeopleIncluded := TList<TPeopleIncluded>.Create; end; procedure FinalizeProcessing; begin PeopleIncluded.Free; end; My question is whether in this situation it is better to declare PeopleIncluded globally rather than locally. I know the theory is to define locally whenever possible, but I would like to know if there are any issues to worry about with regards to doing tens of thousands of of "create"s and "free"s? Making them global will do only one create and one free. What is the recommended method to use in this case? If the recommended method is to still define it locally, then I'm wondering if there are any situations where it is better to define globally when defining locally is still an option.

    Read the article

  • Reusing named_scope to define another named_scope

    - by Sergei Kozlov
    The problem essence as I see it One day, if I'm not mistaken, I have seen an example of reusing a named_scope to define another named_scope. Something like this (can't remember the exact syntax, but that's exactly my question): named_scope :billable, :conditions => ... named_scope :billable_by_tom, :conditions => { :billable => true, :user => User.find_by_name('Tom') } The question is: what is the exact syntax, if it's possible at all? I can't find it back, and Google was of no help either. Some explanations Why I actually want it, is that I'm using Searchlogic to define a complex search, which can result in an expression like this: Card.user_group_managers_salary_greater_than(100) But it's too long to be put everywhere. Because, as far as I know, Searchlogic simply defines named_scopes on the fly, I would like to set a named_scope on the Card class like this: named_scope from_big_guys, { user_group_managers_salary_greater_than(100) } - this is where I would use that long Searchlogic method inside my named_scope. But, again, what would be the syntax? Can't figure it out. Resume So, is named_scope nesting (and I do not mean chaining) actually possible?

    Read the article

  • C++ arrays as parameters, EDIT: now includes variable scoping

    - by awshepard
    Alright, I'm guessing this is an easy question, so I'll take the knocks, but I'm not finding what I need on google or SO. I'd like to create an array in one place, and populate it inside a different function. I define a function: void someFunction(double results[]) { for (int i = 0; i<100; ++i) { for (int n = 0; n<16; ++n) //note this iteration limit { results[n] += i * n; } } } That's an approximation to what my code is doing, but regardless, shouldn't be running into any overflow or out of bounds issues or anything. I generate an array: double result[16]; for(int i = 0; i<16; i++) { result[i] = -1; } then I want to pass it to someFunction someFunction(result); When I set breakpoints and step through the code, upon entering someFunction, results is set to the same address as result, and the value there is -1.000000 as expected. However, when I start iterating through the loop, results[n] doesn't seem to resolve to *(results+n) or *(results+n*sizeof(double)), it just seems to resolve to *(results). What I end up with is that instead of populating my result array, I just get one value. What am I doing wrong? EDIT Oh fun, I have a typo: it wasn't void someFunction(double results[]). It was: void someFunction(double result[])... So perhaps this is turning into a scoping question. If my double result[16] array is defined in a main.cpp, and someFunction is defined in a Utils.h file that's included by the main.cpp, does the result variable in someFunction then wreak havoc on the result array in main?

    Read the article

  • Why can't my function access a variable in an enclosing function?

    - by nailer
    I know about the LEGB rule. But a simple test of whether a function has read access to variables defined in an enclosing function doesn't seem to actually work. Ie: #!/usr/bin/env python2.4 '''Simple test of Python scoping rules''' def myfunction(): print 'Hope this works: '+myvariable def enclosing(): myvariable = 'ooh this worked' myfunction() if __name__ == '__main__': enclosing() Returns: NameError: global name 'myvariable' is not defined Am I doing something wrong? Is there more to it than the LEGB resolution order?

    Read the article

  • Return from parent sub in Perl

    - by JS Bangs
    I want to write a subroutine which causes the caller to return under certain conditions. This is meant to be used as a shortcut for validating input to a function. What I have so far is: sub needs($$) { my ($condition, $message) = @_; if (not $condition) { print "$message\n"; # would like to return from the *parent* here } return $condition; } sub run_find { my $arg = shift @_; needs $arg, "arg required" or return; needs exists $lang{$arg}, "No such language: $arg" or return; # etc. } The advantage of returning from the caller in needs would then be to avoid having to write the repetitive or return inside run_find and similar functions.

    Read the article

  • C++ boost wave, scoped macro

    - by aaa
    hello. Is it possible to have scoped macros using custom defined macros through boost wave? I know it should a possible with C++0x however I am working with regular C++. If it is possible, can you provide link or reference how to accomplish this? Thanks

    Read the article

  • how to access a firefox extension variable from the current document/window

    - by bosky101
    my firefox extension has an object myExt . myExt = { request: function(){ //makes request to server}, callback: function(json) { //do something with this } }; From a dynamically added script element, I make a call to a server that returns json, i want the json to be sent to myExt.callback that exists within my extension's js code. //from my extension, i add a script element myExt.request(); //from server i get the following response myExt.callback ( {"some":"json"}) ; //but the window doesnt find a reference to myExt how do i make a reference to myExt variable from the webpage ?

    Read the article

  • Variable not accessible within and if statment

    - by Chris
    I have a variable which holds a score for a game. My variable is accessible and correct outside of an if statement but not inside as shown below cout << score << endl; //works if(!justFinished){ cout << score << endl; // doesn't work prints a large negative number endTime = time(NULL); ifstream highscoreFile; highscoreFile.open("highscores.txt"); if(highscoreFile.good()){ highscoreFile.close(); }else{ std::ofstream outfile ("highscores.txt"); cout << score << endl; outfile << score << std::endl; outfile.close(); } justFinished = true; } cout << score << endl;//works

    Read the article

  • jquery document.ready multiple declaration

    - by Hendry H.
    I realized that I can specify $(document).ready(function(){}); more than once. Suppose like this $(document).ready(function(){ var abc = "1122"; //do something.. }); $(document).ready(function(){ var abc = "def"; //do something.. }); Is this standard ? Those codes work on my FF (16.0.2). I just a little afraid that other browser may not. What actually happen ? How jQuery handle those code ? Thanks.

    Read the article

  • Returning a private variable in JavaScript

    - by enrmarc
    I don't know why console.log(Set.current_index) shows 0 instead of 3. var Set = (function() { var set = []; var index = 0; function contains(set, e) { for (var i = 0; i < set.length; i++) { if (set[i] === e) { return true; } } return false; } var add = function(e) { if (!contains(set, e)) { set[index++] = e; } } var show = function() { for (var i = 0; i < set.length; i++) { console.log(set[i]); } } return { add: add, show: show, current_index: index }; })();? Set.add(20); Set.add(30); Set.add(40); Set.show(); console.log(Set.current_index);

    Read the article

  • Is it possible to restrict how a method can be called in PHP?

    - by Ashley Ward
    Given that my class looks like this: class Methods{ function a(){ return 'a'; } function b(){ $this->a(); } function c(){ $this->a(); } } Is it possible to ensure that function a can only be called from function b? In the above example function c should fail. I could just include it in function b, but in the future I may want to let a() be called by some new functions (e.g. d() or e())

    Read the article

  • Why does my simple event handling example not work?

    - by njreed
    I am trying to make a simple event handler. (Note, I'm not trying to implement a full-blown publish/subscribe model; I'm just interested in why my example doesn't work as I think it should) var myObj = (function () { var private = "X"; function triggerEvent(eventName) { if (this[eventName]) { this[eventName](); } } // Setter / Getter function getProp() { return private; } function setProp(value) { private = value; triggerEvent("onPropChange"); } // Public API return { // Events "onPropChange": null, // Fires when prop value is changed // Methods "getProp": getProp, "setProp": setProp }; })(); // Now set event handler myObj.onPropChange = function () { alert("You changed the property!"); }; myObj.setProp("Z"); // --> Nothing happens. Wrong // Why doesn't my alert show? I set the onPropChange property of my object to a simpler handler function but it is not being fired. I have debugged this and it seems that in triggerEvent the variable this is referencing the global window object. I thought it should reference myObj (which is what I need). Can someone explain the error in my thinking and how I correct this? Help much appreciated. jsFiddle here

    Read the article

  • Python: why can't descriptors be instance variables?

    - by Continuation
    Say I define this descriptor: class MyDescriptor(object): def __get__(self, instance, owner): return self._value def __set__(self, instance, value): self._value = value def __delete__(self, instance): del(self._value) And I use it in this: class MyClass1(object): value = MyDescriptor() >>> m1 = MyClass1() >>> m1.value = 1 >>> m2 = MyClass1() >>> m2.value = 2 >>> m1.value 2 So value is a class attribute and is shared by all instances. Now if I define this: class MyClass2(object) value = 1 >>> y1 = MyClass2() >>> y1.value=1 >>> y2 = MyClass2() >>> y2.value=2 >>> y1.value 1 In this case value is an instance attribute and is not shared by the instances. Why is it that when value is a descriptor it can only be a class attribute, but when value is a simple integer it becomes an instance attribute?

    Read the article

  • How do I use a named_scope to filter records in my model

    - by kibyegon
    I have a model "Product" with a "description" field. Now I want to have a link in the index page that when clicked will show all products where the description is blank (empty). In the model I have defined a named_scope like this named_scope :no_description, :conditions => { :description => "" } I have checked that the named_scope works by calling Product.no_description.count on the console. As far as I know, the controller is then supposed to handle the filter request from the link on the "index" action but be able to distinguish it from the default which is view all products. def index @products = Product.all ... My problem is getting the controller handle the different request, what route to setup for the link on the view and the actual link on the view. Hope I explained my problem.

    Read the article

  • keeping track of multiple runs of the same function, part 2

    - by qwertymk
    This is related to this Anyway what I need is actually something slightly different I need some way of doing this: function run(arg) { this.ran = this.ran || false; if (!this.ran) init; /* code */ this.ran = true; } This works fine, I just want to make sure that this code works even when this in case it was called with call() or apply() Check this out for what I'm talking about, All of the calls after the first one should all be true, no matter the context

    Read the article

  • Using functions and environments

    - by Eduardo Leoni
    Following the recent discussions here (e.g. 1, 2 ) I am now using environments in some of my code. My question is, how do I create functions that modify environments according to its arguments? For example: y <- new.env() with(y, x <- 1) f <- function(env,z) { with(env, x+z) } f(y,z=1) throws Error in eval(expr, envir, enclos) : object 'z' not found I am using environments to keep concurrently two sets of simulations apart (without refactoring my code, which I wrote for a single set of experiments).

    Read the article

  • Difference between :: and -> in PHP

    - by vrode
    I always see people in serious projects use :: everywhere, and - only occasionally in local environment. I only use - myself and never end up in situations when I need a static value outside of a class. Am I a bad person? As I understand, the only situation when -> won't work is when I try following: class StaticDemo { private static $static } $staticDemo = new StaticDemo( ); $staticDemo->static; // wrong $staticDemo::static; // right But am I missing out on some programming correctness when I don't call simple public methods by :: ? Or is it just so that I can call a method without creating an instance?

    Read the article

  • How can a Perl force its caller to return? [closed]

    - by JS Bangs
    Possible Duplicate: Is it possible for a Perl subroutine to force its caller to return? I want to write a subroutine which causes the caller to return under certain conditions. This is meant to be used as a shortcut for validating input to a function. What I have so far is: sub needs($$) { my ($condition, $message) = @_; if (not $condition) { print "$message\n"; # would like to return from the *parent* here } return $condition; } sub run_find { my $arg = shift @_; needs $arg, "arg required" or return; needs exists $lang{$arg}, "No such language: $arg" or return; # etc. } The advantage of returning from the caller in needs would then be to avoid having to write the repetitive or return inside run_find and similar functions.

    Read the article

  • What characteristic of a software determines its operational scope?

    - by Dark Star1
    How can I classify whether a software is a medium with the ability to grow into an enterprise level software or whether it is already there? And how should I use the information to choose the appropriate language/tool to create the software? At first I was asking whether Java or PHP is the best tool to design enterprise level software, however I've suddenly realized that I am unable to put the software I'm tasked with redesigning into the proper scope so I'm lost. Edit: I guess I'm looking for tell tale signs in software that may tip the favour towards enterprise level type software in the sense of functional and operational characteristics; functional: what it does (multi-functional), Architectural characteristics such as highly modular. operational: multi-sourced and multi-homed, databases, e.t.c. To be honest the reason I ask is because I'm skeptical about the use of PhP to design a piece of employee and partial accounting software. I'm more tipping towards the use of JSP and an hmvc framework such as JSF, wickets, e.t.c. where as the other guy wants to go the PhP way although I'm not experienced with PhP, as far as I know it's not an OO oriented language hence my skepticsm towards it.

    Read the article

< Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >