Menu
  • HOME
  • TAGS

Empty elements in JS array declaration

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...

C++ - what's the best way to initialize a variable in one function/file and then use it in main()/another file?

c++,variables,declaration

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...

Reconciling declaration and usage syntax of arrays in C

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...

What is this fortran parameter declaration doing and why is it doing it?

fortran,declaration

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,...

C - Send array to function without declaring it [duplicate]

c,arrays,declaration

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++, Class: Out-of-line declaration of a member error?

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 declarations inside function scopes?

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 instance variable declaration

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...

vb.net: list of typed class, how to add items like C#?

.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"}) ...

Trying to declare and initialize varible but it will lead to compilation fail [duplicate]

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 =...

Generic type-Object type mismatch in java

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...

Error w/declaration on else statement (C++)

c++,if-statement,declaration

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 <<...

how to declare a variable in Netezza?

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...

Why are declarations necessary

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...

Class declaration in same scope as using declaration compiles in GCC but not MSVS

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...

override func viewDidLoad

swift,override,declaration

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,...

Can't declare class constant nor property variable

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....

Array declaration in FORTRAN for beginners

arrays,fortran,declaration

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 - While loop before variables not compiling [duplicate]

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...

variable declaration not allowed here

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) {...

Why can't we declare constants with default value?

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....

Error: Not found: Value S (Scala)

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...

Unqualified name lookup of the name declared into the function body

c++,declaration,name-lookup

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...

Incompatible Declaration in Implementation file in C++

c++,declaration

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 of Pointers, why is it declared this way?

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++ member access into incomplete type although header is included

c++,declaration,member,forward,incomplete-type

You defined a type Torse, but clang complains about a type named torse. Fix your case....

Haskell Function Definition without ->

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...

(this) after function declaration

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...

Unusual C++ function declaration

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...

Why redeclaration of a static member is denied

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. ...

Redeclaration Error

c++,c,declaration,definition

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; /*...

Why is counter not being intialised in the said for loop? [closed]

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++) {...

Definition of def, cdef and cpdef in cython

python,declaration,cython

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...

Why is it necessary to declare a string's length in an array of strings in C?

c,arrays,string,declaration

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] =...

function declaration without definition

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();.

Does C provide a way to declare an extern variable as 'read-only', but define it as writeable?

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...

Where to write the definition? [duplicate]

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...

Can you create an object in Javascript without declaring every value, and how?

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...

Why is there not any warning on a declaration without initialization in a for loop?

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,...

Build a Node package using Typescript 1.5 and generate the declaration file

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...

Redeclaration of the exception parameter

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,...

Names and types in c++ [closed]

c++,types,declaration,names

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,...

Inject sub module to main module

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...

Is class member declaration not a statement?

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...

arrayVariable() As Object vs. arrayVariable As Object() – not the same in Property declaration?

arrays,vb.net,declaration

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...

Declaration issue with using curry in point-free style in Haskell

haskell,declaration,pointfree

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 (+)...

What type of the definition is int a?

c++,declaration

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...

Declaration of differents types of extern variables in C

c,pointers,declaration,extern

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)...

Is it necessary to Initialize / Declare variable in PHP?

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 Language Parsing: Distinguish function expressions and declarations

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...

Which declaration to use in swift [duplicate]

variables,swift,declaration

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...

How do I pass parameters to a method both as normal and like a property?

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...

How (may?) I export Ada type based on a “new” type from a generic?

generics,declaration,ada

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...

Python declaration order: classes or functions first?

python,declaration,pep8

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...

Placement of iterator declarations in C11 (coding style)

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...

Is it bad practice to instantiate C struct object as global variable?

c,struct,declaration

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...

What is the point of declaring a variable as one class, and allocating memory to it with another class?

ios,objective-c,declaration

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...

Can't understand the declaration #3 in the Example of [basic.link]/6 C++14

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...

Class declaration with a specified base class

c++,class,declaration

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....

Initializing objects using a super class instead of the subclass

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...

Program with chaining of using-declarations compiles on MSVS and clang but not on GCC

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...

Passing an array to a function c++

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:...

Why does the compiler say that the variable “z” is redeclared as a different variable type?

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...

Whether redeclare a const static variable outside a class or not

c++,static,const,declaration

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...

I don't understand this c++ array declaration

c++,arrays,declaration

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...

Java array type declaration

java,arrays,types,declaration

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...

Declarations of a class name and a variable with the same name

c++,declaration

// 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...

Usage of enum name as value identifier in Objective-C

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 confusion?

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,...

Why can't you declare a variable inside the expression portion of a do while loop?

c++,declaration,do-while

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...

Swift expecting declaration but already declared

swift,alert,declaration

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: setting a key on the object by combining previously defined keys [duplicate]

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 Variable declaration not allowed here

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....

Scope Errors with Switch statement

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...

What is the type of XSynchronize in this code?

c,declaration

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 dependency injection, array, $inject, factory

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...

Has the new C++11 member initialization feature at declaration made initialization lists obsolete?

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....

Function returning another function

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. ...

How to best handle C++ object initialization: empty constructors or pointers?

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);...

Scope of declarations in the body of a do-while statement

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...

How to declare a pred for a predicate that imports or outputs lists?

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...

Does redeclaring variables in C++ cost anything?

c++,performance,declaration

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 'declared but not used' compiler error in this simple program?

go,declaration

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...

Declare variables inside loops the right way?

c++,loops,declaration

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>...

Do I need to declare every property in a PHP object

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...

Counter as variable in for-in-loops

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: Undefined variable

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',...

Variable declaration via macro into inline function

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.

Need help passing a Struct to a function locally in C

c,struct,declaration

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 */...

Correct type declaration for method returning iterator to C array

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; };...

Input Mask with angular-input-masks

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# help declaring variable i initialize it to

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 ++); ...

Should variables always be declared with interface in Java?

java,list,declaration

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...

Angular: when using ng-include, number variable become NaN [duplicate]

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...