javascript,jquery,arrays,declaration
Best solution: Use .filter var arr = [1, 2, 3].filter(function(value){ return value == 2 }); If the return value is true, the element is included in the returned array, otherwise it is ignored. This is pure js, so you don't need jquery. See documentation about .filter Your problem: Use .push...
Use structures: struct data { int x; int y; }; data Init() { data ret; ret.x = 2; ret.y = 5; return ret; } int main() { data v = Init(); SomeFunction(v.x, v.y); //or change the function and pass there the structure return 0; } If you don't want to...
c,arrays,pointers,syntax,declaration
The general inspiration behind C's (admittedly confusing) declaration syntax is that "declaration follows use". So, for example: int *ptr; happens to declare ptr as an object of type int* (which is why some people prefer to write int* ptr;), but if you follow the syntax what it really means is...
The code program main implicit none integer :: param parameter (param=((0-565))) ! integer, parameter :: param = -565 ! suggest replacing two lines above with this print*,"param =",param end program main sets param to -565, as confirmed by both g95 and gfortran. The comment line uses a suggested modern syntax,...
Yes. You can. In C99/11 you can do by using compound literals: C11: 6.5.2.5 Compound literals: A postfix expression that consists of a parenthesized type name followed by a braceenclosed list of initializers is a compound literal. It provides an unnamed object whose value is given by the initializer list.99)....
c++,arrays,class,compiler-errors,declaration
You should remove the semicolons in the cpp file. void Array::addTings (float itemValue); should be void Array::addTings (float itemValue) Correct code is: void Array::addTings (float itemValue) // Out-of-line declaration ERROR { std::cout << "How many items do you want to add to the array"; std::cin >> arraySize; } float Array::getTings...
c++,function,scope,declaration
Although I had no idea you can do this, I tested it and it works. I guess you may use it to forward-declare functions defined later, like below: #include <iostream> void f() { void g(); // forward declaration g(); } void g() { std::cout << "Hurray!" << std::endl; } int...
ios,objective-c,declaration,ivar
From the point of view of the USE, there is not difference. From the point of view of the declaration, the first one is a Category: @interface MyCustomObject() { } so if you have a variable with the same name in the header file, your implementation file will see this...
.net,vb.net,declaration,generic-list
Yes it is possible using the With keyword: Dim list As New List(Of Articulo)() list.add(New Articulo() With {.Id = 1, .Name="xxx1"}) list.add(New Articulo() With {.Id = 2, .Name="xxx2"}) ...
java,variables,instance,declaration
You are declaring a new class which is instantiated (i.e. you use the new keyword) so you have to initialize in the constructor like so: class Hello { public int a; public Hello(){ a = 10; } } Or use an inline initializer: class Hello { public int a =...
java,generics,linked-list,declaration,type-mismatch
Your inner class Node is generic, but you're using the raw form of the class. That means that a method that returns V gets type-erased, and it is now returning Object. But the Node class doesn't need to be generic. A non-static nested class (i.e. a nested class) can use...
You should end the if before you start your else part : int main() { int max = 10; int min = 0; while(cin >> min){ if(min<max){ ++min; //dont understand why do you do this ! cout << "The number inputted is well in the RANGE: " << min <<...
sql,variables,declaration,netezza
Unfortunately, there are no procedural SQL extensions in Netezza that allow you to employ variables like this as part of the SQL language itself. Purely SQL solutions would involve kludges such as joining to a CTE returning that one value. However, the NZSQL CLI does allow the use of session...
c#,.net,variables,clr,declaration
Of course, that would be possible. I can think of a few reasons you don't want this: What is the scope of your variable? Not clear if you don't tell the compiler. Will animals in two methods become a private variable or two method scoped variables? What if the name...
c++,declaration,language-lawyer,using-declaration
I believe the program is ill formed. [basic.scope.declarative]/4 says: Given a set of declarations in a single declarative region, each of which specifies the same unqualified name, — they shall all refer to the same entity, or all refer to functions and function templates; or — exactly one declaration shall...
Just move the body of one of the two into the other one, except for this line super.viewDidLoad(), which must be called once: override func viewDidLoad() { super.viewDidLoad() title = "Media picker..." buttonPickAndPlay = UIButton.buttonWithType(.System) as? UIButton if let pickAndPlay = buttonPickAndPlay{ pickAndPlay.frame = CGRect(x: 0, y: 0, width: 200,...
php,class,properties,constants,declaration
public and const are only available as of PHP 5. var is used in PHP 4. Support for PHP 4 has been discontinued since 2007-12-31. Please consider upgrading to PHP 5. Upgrade maybe? PHP 5 has been around for 11 years and PHP 4 discontinued for 7....
Regardless of the type, <type>,dimension(5) :: b and <type> :: b(5) are identical and denote an array of length 5. <type> can be e.g. character, integer, real, logical, etc. character(5) is a short-hand of character(len=5) and declares a string of length 5. If the length is omitted, it is assumed...
c,variables,loops,while-loop,declaration
In C89 all variables should be declared at the top of a code block i.e. directly after a {, they don't have to be declared at the top of a function. In C99 and later they can be declared anywhere. If you have a section of code in your function...
variables,foreach,hashmap,declaration,hashset
A declaration is not a statement, so it's not allowed in that spot. If it were, answer would be out of scope at the if statement anyways. Use a block scope to declare and use answer: private HashMap<String, String> answers; public String generateResponse(HashSet<String> word) { for(String word : words) {...
java,constants,declaration,default-value,final
Because that wouldn't make much sense. How many immutable primitive constants with default value would you need in your lifetime? For reference, see https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html - the only actual values you'd get as constants are literal 0 (cast to different numeric types, but still a 0, mind me), false and null....
arrays,scala,naming-conventions,declaration
When you are creating the k and s identifiers with val Array(k,s) = ..., you are using pattern matching to define them. From the Scala Specifications (1.1 Identifiers): The rules for pattern matching further distinguish between variable identifiers, which start with a lower case letter, and constant identifiers, which do...
1. No, it denotes the global foo(). In main you are redeclaring the name, not defining it. If there were another definition of foo, then it would violated One Definition Rule, and the program would not compile. 2. I guess the first answer also answers this. There is only one...
void setCourseName(std::string); // declaration in .h void GradeBook::setCourseName() const // implementation in .cpp void setInstructorName(std::string); // declaration in .h void GradeBook::setInstructorName() const // implementation in .cpp See the difference? Your implementations are missing the name parameter and have trailing const modifiers. You need to correct those mistakes: void GradeBook::setCourseName(std::string name)...
c++,arrays,pointers,declaration
A string literal is an array in read-only memory (meaning the chars in that array are intrinsically immutable). We typically represent C-style strings with a pointer to their first character. For a literal, where the chars are const, this pointer has type const char*. If you wanted an array of...
c++,declaration,member,forward,incomplete-type
You defined a type Torse, but clang complains about a type named torse. Fix your case....
function,haskell,declaration,definition
maxCollatz is a pair of integers (Integer, Integer). It's not a function, it takes no arguments, and isn't called to produce anything; it just is a pair of integers. The syntax for declaring the types of and then implementing top level declarations in Haskell is syntax for defining values. Functions...
javascript,function,variables,scope,declaration
This whole structure is a means of saving the current value of this so that a function call later on can use it. That could all be done also with .bind() like this which (if you understand what .bind() does might be easier to follow): function myFunc(_this) { // do...
c++,function,prototype,declaration
One difference is that enclosing it in parenthesis prevents the function-like macros expansion by the preprocessor. As mentioned in the other answers it makes no difference though to the actual compiler. For instance: // somewhere buried deep in a header #define function(a, b) a + b // your code void...
c++,declaration,static-members
C++11 9.2/1 [class.mem] A member shall not be declared twice in the member-specification, except that a nested class or member class template can be declared and then later defined, and except that an enumeration can be introduced with an opaque-enum-declaration and later redeclared with an enum-specifier. ...
A definition is always a declaration. The difference is that a definition also gives whatever you declare some value. In your example, by the way, it is only a redeclaration error: f(int a, /* Defines a */ int b) { int a; /* Declares a - error! */ a=20; /*...
java,initialization,declaration
You have a three main issue: You missed the if opening bracket. You have to remove the semicolon at the end of if statement You need to remove the second increment for the counter So try to change your code like: for(int counter = 0; counter < arraytest.length; counter++) {...
def declares a function in Python. Since Cython is based on C runtime, it allows you to use cdef and cpdef. cdef declares function in the layer of C language. As you know (or not?) in C language you have to define type of returning value for each function. Sometimes...
If you're fine with constant strings, then you don't. const char *strings[] = { "foo", "bar", "baz", "quux", }; The only time when you'd need to give it the length of the strings is if you were trying to make a two dimensional array of chars, like char strings[][5] =...
c++,function,c++11,declaration,definition
Since x() is never called, there's nothing to link so no error from linker that it's not defined. It's only declared as a function taking no arguments and returning an X: X x();.
c,embedded,const,declaration,extern
Within the library there is a variable that should be read-only to the application that links the library, but can be modified from within the compilation unit that defines it. The solution is to use object-oriented design, namely something called private encapsulation. module.h int module_get_x (void); module.c static int...
c,initialization,declaration,definition
It is perfectly fine to declare/define variables anywhere inside the body of a statement/function. In an old, withdrawn version of the C standard called "C90", you were forced to always declare/define variables at the beginning of a block. However, this restriction was removed ages ago. It may still be convenient...
javascript,variables,object,declaration
If you really need separate instance variables for north, south, east and west, I'd suggest something like this where you can pass just the directions that you care about in a space delimited string. This makes the calling code much simpler since you don't have to pass anything for the...
c++,initialization,g++,warnings,declaration
Thanks to Pradhan who gave this link, I undestood the problem. This link states the following: GCC has the ability to warn the user about using the value of a uninitialized variable. Such value is undefined and it is never useful. It is not even useful as a random value,...
node.js,typescript,declaration
There are lots of ways to do this as there is no official support yet. You can track the official support here: https://github.com/Microsoft/TypeScript/issues/2338 However I use https://github.com/TypeStrong/atom-typescript#packagejson-support Sample project on NPM: https://github.com/basarat/ts-npm-module Sample project using the project from NPM: https://github.com/basarat/ts-npm-module-consume...
c++,declaration,language-lawyer
The standard means precisely what it says. A program which redeclares the name used in the exception-declaration (e in your case) in the outermost block of the compound-statement of the handler is ill-formed, since it violates a "shall" rule (the very one you quote). If your compiler accepts it silently,...
A declaration can introduce a type, a function, a variable. class A; // This declares a type, A A* aPtr; // This declares a variable, aPtr // The type of aPtr is A* A foo(); // This declares a function, foo. In your case, List<Observer*> *_Observers; // Declares a variable,...
javascript,angularjs,declaration,angularjs-controller,angularjs-module
You are messing up with module declaration. You declared angular.module('app.newProject') two times. While creating it first time you registered SelectionCtrl. After that you created another module with same name angular.module('app.newProject,[]') with dependancy and registered TabController1 controller. When you created second module it overrides first one & now it has only...
c#,declaration,terminology,statements
declaration statement can be seen as a subset of declaration. Eventually declaration statement is the intersection of statement and declaration. Now concerning members, you have to know which kind of member you are dealing with. For class you have class member declaration etc... By reading your comment I think you...
The problem is that they are Properties so the () is ignored as an Array specifier and thinks of it as an empty parameter collection. Look at how the compiler see them - even the compiler thinks you had an Object and not a Object() and so in your example...
You should pass (+) to uncurry: add :: (Int, Int) -> Int add = uncurry (+) This is because uncurry is a function that takes a binary function and returns an unary function: uncurry :: (a -> b -> c) -> ((a, b) -> c) Your binary function is (+)...
explicit-instantiation is a template-related declaration, where a template class is explicitly instantiated for a particular type by a declaration. Example (from § 14.7.2 draft N3337) template<class T> class Array { void mf(); }; // explicit instantiation of Array template class for char // leads to all functions being instantiated too...
long a ; strc_1 s ; These in main.c are called definitions, not declarations. (To be precise, all definitions are also declarations). The reason you don't have to define ss is because it's defined in some other source file. As long as the declaration of ss (which is in header1.h)...
php,variables,initialization,declaration
PHP does not require it, but it is a good practice to always initialize your variables. If you don't initialize your variables with a default value, the PHP engine will do a type cast depending on how you are using the variable. This sometimes will lead to unexpected behaviour. So...
javascript,parsing,expression,declaration,abstract-syntax-tree
I'm also writing a JavaScript parser - for Java, with JavaCC. Is it "en vogue"? :) I'm no way an expert so my terminology may be somewhat household level, please excuse that. If I understood your idea right, seems like you want to distinguish function declarations and expressions on the...
The Float? is an optional. The Float! is an implicitly unwrapped optional. For details on the latter, see the Implicitly Unwrapped Optionals section of The Swift Programming Language: The Basics, which says: [Optionals] indicate that a constant or variable is allowed to have “no value”. Optionals can be checked with...
vb.net,visual-studio-2013,declaration,realbasic,xojo
When I look at the documentation for the Xojo Assigns keyword the closest thing I can think of is to create a write-only property like this: Public WriteOnly Property theVolume(a As Integer, b As Integer) As Integer Set(c As Integer) Debug.WriteLine("a={0}, b={1}, c={2}", a, b, c) End Set End Property...
The spec you propose looks fine: with Ada.Strings.Bounded; package Command_Interface is Command_Max : constant := 200; package Command_String_Type is new Ada.Strings.Bounded.Generic_Bounded_Length (Max => Command_Max); procedure Send_Command (Command_String : in Command_String_Type.Bounded_String); end Command_Interface; and so does the body (this is a demo, of course): with Ada.Text_IO; package body Command_Interface is procedure...
Generally, there is no preferred order. Depending on the program, a order can be needed: You can decorate classes with functions. Then the decorator function must be defined before the class. OTOH, you can decorate functions with classes. Then the decorator class must be defined before the function. You can...
c,coding-style,declaration,c11
Where did you get this idea? The C11 draft, section 6.8.5 (1), says: iteration-statement: while ( expression ) statement do statement while ( expression ) ; for ( expressionopt ; expressionopt ; expressionopt ) statement for ( declaration expressionopt ; expressionopt ) statement That last form makes it pretty clear...
I'm not sure what is the question about exactly, but here are some thoughts. instanceOfB is a global variable, right? So, it is an evil that should be avoided if not strictly necessary. On the contrary, struct A instanceOfA; inside function body looks fine for me, though we usually move...
The benefit is that you can hide implementation details to yourself and to the outside. If you are going to return this value from a method for example, the outside may not care about what kind of image view it is - as long as it is some kind of...
c++,declaration,language-lawyer,c++14,extern
This is subject to active issue 426 which says: An example in 3.5 [basic.link] paragraph 6 creates two file-scope variables with the same name, one with internal linkage and one with external. static void f(); static int i = 0; //1 void g() { extern void f(); // internal linkage...
About standard(n3797): 9.1 Class names: A class declaration introduces the class name... A declaration consisting solely of class-key identifier; is either a redeclaration of the name in the current scope or a forward declaration of the identifier as a class name. It introduces the class name into the current scope....
object,inheritance,declaration
You could instantiate every other class with object, but not primitives, though even they have wrappers that make them classes. It's just not good object oriented practice because you want the program to be as fail safe as possible. Put more varied methods into those classes and that's when you...
c++,declaration,language-lawyer,using-declaration
Clang and MSVC are correct; this code is valid. As Alf notes, [namespace.udecl] (7.3.3)/10 says A using-declaration is a declaration and can therefore be used repeatedly where (and only where) multiple declarations are allowed. However, there is no restriction on multiple declarations of the same entity in block scope, so...
c++,arrays,function,reference,declaration
These three lines: void printDeck(Card deck[]); void printDeck(Card p1[]); void printDeck(Card p2[]); declare the same function. They are equivalent to saying: void printDeck(Card []); void printDeck(Card []); void printDeck(Card []); If you want to print all the decks in one function call, you need to change the function declaration to:...
c,function,compiler-errors,declaration
You did a few things wrong: (From the comments of BLUEPIXY, Also you should avoid the name div, since a few standard library's use it) #include <stdio.h> /*Prototypes*/ float divve(int x, int z); //^^^^^ Changed name of the function since you have a float variable with the same name in...
There's an exception to that rule for const static members that: Are of integer or enumeration type (pointers, references, floats need not apply) Never have their address taken or get bound to a reference For static constexpr members, the type restriction is dropped (or, replaced with those of constexpr), and...
int myArray[8] = {0,}; It's the same as int myArray[8] = {0}; will populate the whole array with 0; This is allowed in case that someone would want to add more elements to that array. For example : int myArray[] = { 1, 2, 3, }; Can easily be populated...
On this specific case it may seem verbose and redundant, but since we're dealing with OO language, it's very likely (and useful) to run into declarations like: Shape shape = new Triangle(); //where Triangle implements Shape interface Same reason goes here, an Array could be of general type and contain...
// Exactly one class may have the name: struct A; // Declaration of a new class. struct A { }; // Definition, but not a declaration of a new name. Doesn't count. // Aside from the class, exactly one variable may share the name: extern int A; // Declaration of...
objective-c,enums,namespaces,declaration,redefinition
Objective-C is C. An enum is a C enum. And there is no namespacing. That is exactly why the convention is to name the enumerations AnEnumAnyValue and AnotherEnumAnyValue. You'll find that all Cocoa enumerations work that way: typedef enum { UIViewAnimationTransitionNone, UIViewAnimationTransitionFlipFromLeft, UIViewAnimationTransitionFlipFromRight, UIViewAnimationTransitionCurlUp, UIViewAnimationTransitionCurlDown, } UIViewAnimationTransition; If you want...
c++,object,declaration,new-operator
To answer the question in the comment, yes there is a difference. When you do node* q = new node() you declare a pointer to a node object, and then at runtime dynamically allocate memory enough for one node object, and calls the default constructor (alternatively, value initializes the object,...
It seems like scoping would be the issue, what would be the scope of i declared in the while portion of a do while statement? It would seem rather unnatural to have a variable available within the loop when the declaration is actually below the loop itself. You don't have...
You can't subclass UIAlertController, for one thing. Second of all, you can only interact with object properties inside of methods, functions, or the global scope. Run this code inside of the view controller where you plan on presenting your alert: class viewController: UIViewController { var alertThenGenerateNewThingController: UIAlertController = UIAlertController() var...
javascript,arrays,object,declaration,key-value
You can't do what you're asking with a "static" declaration like you show because this is not set to the object in a static declaration so you can't refer to other properties of the object using this, but if you want the same logic for making the fullName property, you...
java,variables,if-statement,int,declaration
string must be changed to String. By writing int score you're trying to declare a new variable... that already exist, you declared it before. Just remove the int part, you will get the assignment you want....
c++,scope,switch-statement,declaration
This is a common scoping error { int j =1; } cout<<j<<endl; The value of j is only accessible inside the brackets and not outside it i.e. the cout statement will give an error. You can use the following workaround for your task. switch(i){ case 0:{ Class0* Ptr = new...
XSynchronize is a function that takes two arguments: (pointer to Display, int). It returns a pointer to a function that takes one argument: (pointer to Display), and returns an int. Useful link: http://cdecl.org/...
angularjs,dependencies,declaration,factory,code-injection
Three steps that work for me (plunkr): 1. Be sure you define a module's dependencies only once. Indeed, check that angular.module('anglober.services', [...]); is indeed called only once with the second argument. At the same time, be sure to call these lines before the actual services/controllers /... definitons. 2. Wire every...
c++,c++11,constructor,initialization,declaration
No, they are not obsolete as this article Get to Know the New C++11 Initialization Forms says in the Class Member Initialization section (emphasis mine): Bear in mind that if the same data member has both a class member initializer and a mem-init in the constructor, the latter takes precedence....
c++,declaration,language-lawyer
I've read the section 8.3.5 of the current C++ standard Obviously not very carefully. §8.3.5 [dcl.fct]/p8: Functions shall not have a return type of type array or function, although they may have a return type of type pointer or reference to such things. ...
c++,pointers,object,initialization,declaration
If you want to construct it only once and it can be done in the initialization of the class then you dont need a pointer. You can declare it as a member and initialize it in the constructor like so: HPP class Game { private: Window window_; public: Game(int, int);...
c++,declaration,language-lawyer,do-while
So currently as a the do while exists the body of the loop is a block: do { // begin block int i = get_data(); // whatever you want to do with i; } //end block while (i != 0); so how does a block scope work, from section 3.3.3...
list,declaration,predicate,mercury
List is a parametric type, parametric types take one or more parameters. In the case of list the parameter says what this is a list of. You may have a list of numbers, a list of strings, a list of pumpkins or a list of lists of numbers (any valid...
I benchmarked this particular code, and even WITHOUT optimisation, it came to almost the same runtime for both variants. And as soon as the lowest level of optimisation is turned on, the result is very close to identical (+/- a bit of noise in the time measurement). Edit: below analysis...
How to fix the compiler message? Remove the outer i from your program: package main import "fmt" func main() { x := [5]float64{1, 2, 3, 4, 5} var total float64 = 0 for i, value := range x { total += value fmt.Println(i, value) } fmt.Println("Average:", total/float64(len(x))) } Surely...
As mentioned by πάντα ῥεῖ in the comments, you can't create new variable names dynamically at runtime in C++. All variable names must be known at compile-time. What you need to do here is use array indices instead. For example, change somedata and Do to std::vectors. Something like this: std::vector<bool>...
php,oop,object,properties,declaration
You should declare only the public properties which define the concept represented by the object. This means that first you need to define WHAT is the single responsibility of the object. Then expose the properties you want used by other objects. Don't expose internal details i.e things that another object...
variables,swift,constants,declaration,for-in-loop
To understand why i can’t be mutable involves knowing what for…in is shorthand for. for i in 0..<10 is expanded by the compiler to the following: var g = (0..<10).generate() { while let i = g.next() { // use i } Every time around the loop, i is a freshly...
laravel,laravel-4,eloquent,declaration,laravel-5
public function viewstudentAttendance() { //This code turns ID ONLY Check the website out for a code that retrieves data so you can loop it. $students = Auth::user() - > id; //Code that counts number of student $studentCount = XXX(Google It) //load view and pass users return View::make('student.view') - > with('attendances',...
c,inline,declaration,c-preprocessor
No. You can't. In case of inline function you need to allocate memory on heap and then return a pointer to that allocated memory.
You should declare the structure before the main. struct Rect { double x; double y; char color; double width; double height; } /* Place here the function definitions */ int main (int argc, char *argv[]) { struct Rect a, b, *rec; ... } /* place here the function code */...
c++,arrays,types,iterator,declaration
std::iterator is meant to be used as a base class. From 24.4.2/1: namespace std { template<class Category, class T, class Distance = ptrdiff_t, class Pointer = T*, class Reference = T&> struct iterator { typedef T value_type; typedef Distance difference_type; typedef Pointer pointer; typedef Reference reference; typedef Category iterator_category; };...
angularjs,angular-ui,declaration,mask,angularjs-ui-utils
Declare module like below. angular.module('app',['ui.utils.masks']) And then change ng-app on HTML like below. ng-app="app" This would help you. Thanks....
c#,variables,declaration,increment,decrement
Yes, the output is correct: // This line increments the variable then prints its value. Console.WriteLine("{0}", ++ Cash); // This prints the value of the (incremented variable) Console.WriteLine("{0}", Cash); // The prints the value of the variable *then* increments its value Console.WriteLine("{0}", Cash ++); ...
To emphasize what Oliver Charlesworth said in the comment: The most crucial difference whether this information is public or not. From the way how the question is written, it seems like you're talking about a field (and not a method parameter or return value). And a private field is, per...
javascript,angularjs,declaration,prototypal-inheritance,angularjs-ng-include
@Josh Beam Answered & explained ng-include creates a child scope on creating the DOM. I'd suggest you to use dot rule in angular that will follow prototypal inheritance on that object and you object value will access in child scope. Now your object structure will changed to $scope.model={}; and this...