variable-assignment

What can I do with a moved-from object?

假如想象 提交于 2019-11-26 00:07:38
问题 Does the standard define precisely what I can do with an object once it has been moved from? I used to think that all you can do with a moved-from object is do destruct it, but that would not be sufficient. For example, take the function template swap as defined in the standard library: template <typename T> void swap(T& a, T& b) { T c = std::move(a); // line 1 a = std::move(b); // line 2: assignment to moved-from object! b = std::move(c); // line 3: assignment to moved-from object! }

Java: define terms initialization, declaration and assignment

孤街醉人 提交于 2019-11-25 23:49:24
问题 I find the defs circular, the subjects are defined by their verbs but the verbs are undefined! So how do you define them? The Circular Definitions initialization: to initialize a variable. It can be done at the time of declaration. assignment: to assign value to a variable. It can be done anywhere, only once with the final-identifier. declaration: to declare value to a variable. [update, trying to understand the topic with lambda calc] D(x type) = (λx.x is declared with type) A(y D(x type)) =

What does the keyword Set actually do in VBA?

拥有回忆 提交于 2019-11-25 23:03:39
问题 Hopefully an easy question, but I\'d quite like a technical answer to this! What\'s the difference between: i = 4 and Set i = 4 in VBA? I know that the latter will throw an error, but I don\'t fully understand why. 回答1: set is used to assign a reference to an object. The C equivalent would be int i; int* ref_i; i = 4; // Assigning a value (in VBA: i = 4) ref_i = &i; //assigning a reference (in VBA: set ref_i = i) 回答2: In your case, it will produce an error. :-) Set assigns an object reference

Why can&#39;t I do assignment outside a method?

不问归期 提交于 2019-11-25 22:57:48
问题 If I try to assign a value to a variable in a class, but outside a method I get an error. class one{ Integer b; b=Integer.valueOf(2); } but, if I initialize it during the creation, it works. class one{ Integer b=Integer.valueOf(2); } Inside a method, it works in both cases. 回答1: you need to do class one{ Integer b; { b=Integer.valueOf(2); } } as statements have to appear in a block of code. In this case, the block is an initailiser block which is added to every constructor (or the default

What is the difference between shallow copy, deepcopy and normal assignment operation?

て烟熏妆下的殇ゞ 提交于 2019-11-25 22:57:21
问题 import copy a = \"deepak\" b = 1, 2, 3, 4 c = [1, 2, 3, 4] d = {1: 10, 2: 20, 3: 30} a1 = copy.copy(a) b1 = copy.copy(b) c1 = copy.copy(c) d1 = copy.copy(d) print(\"immutable - id(a)==id(a1)\", id(a) == id(a1)) print(\"immutable - id(b)==id(b1)\", id(b) == id(b1)) print(\"mutable - id(c)==id(c1)\", id(c) == id(c1)) print(\"mutable - id(d)==id(d1)\", id(d) == id(d1)) I get the following results: immutable - id(a)==id(a1) True immutable - id(b)==id(b1) True mutable - id(c)==id(c1) False mutable

JavaScript OR (||) variable assignment explanation

帅比萌擦擦* 提交于 2019-11-25 22:55:57
问题 Given this snippet of JavaScript... var a; var b = null; var c = undefined; var d = 4; var e = \'five\'; var f = a || b || c || d || e; alert(f); // 4 Can someone please explain to me what this technique is called (my best guess is in the title of this question!)? And how/why it works exactly? My understanding is that variable f will be assigned the nearest value (from left to right) of the first variable that has a value that isn\'t either null or undefined, but I\'ve not managed to find

Why don&#39;t Java&#39;s +=, -=, *=, /= compound assignment operators require casting?

匆匆过客 提交于 2019-11-25 21:41:39
问题 Until today, I thought that for example: i += j; Was just a shortcut for: i = i + j; But if we try this: int i = 5; long j = 8; Then i = i + j; will not compile but i += j; will compile fine. Does it mean that in fact i += j; is a shortcut for something like this i = (type of i) (i + j) ? 回答1: As always with these questions, the JLS holds the answer. In this case §15.26.2 Compound Assignment Operators. An extract: A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T

How can I index a MATLAB array returned by a function without first assigning it to a local variable?

不想你离开。 提交于 2019-11-25 21:41:21
问题 For example, if I want to read the middle value from magic(5) , I can do so like this: M = magic(5); value = M(3,3); to get value == 13 . I\'d like to be able to do something like one of these: value = magic(5)(3,3); value = (magic(5))(3,3); to dispense with the intermediate variable. However, MATLAB complains about Unbalanced or unexpected parenthesis or bracket on the first parenthesis before the 3 . Is it possible to read values from an array/matrix without first assigning it to a variable

Command not found error in Bash variable assignment

こ雲淡風輕ζ 提交于 2019-11-25 21:36:49
问题 I have this script called test.sh: #!/bin/bash STR = \"Hello World\" echo $STR when I run sh test.sh I get this: test.sh: line 2: STR: command not found What am I doing wrong? I look at extremely basic/beginners bash scripting tutorials online and this is how they say to declare variables... So I\'m not sure what I\'m doing wrong. I\'m on Ubuntu Server 9.10. And yes, bash is located at /bin/bash . 回答1: You cannot have spaces around your '=' sign. When you write: STR = "foo" bash tries to run

Creating an array from a text file in Bash

纵然是瞬间 提交于 2019-11-25 19:38:37
A script takes a URL, parses it for the required fields, and redirects its output to be saved in a file, file.txt . The output is saved on a new line each time a field has been found. file.txt A Cat A Dog A Mouse etc... I want to take file.txt and create an array from it in a new script, where every line gets to be its own string variable in the array. So far I have tried: #!/bin/bash filename=file.txt declare -a myArray myArray=(`cat "$filename"`) for (( i = 0 ; i < 9 ; i++)) do echo "Element [$i]: ${myArray[$i]}" done When I run this script, whitespace results in words getting split and