assignment-operator

Non-owning holder with assignment semantics

I have a class that should hold a reference to some data, without owning that data (i.e. the actual data is guaranteed not to go out of scope). In particular, the class cannot make a copy – the data is easily several gigabytes in size. Now, the usual implementation (I assume) is to have a reference to the data: struct holder_ref { ...

What is the difference between “=” and “=&” when assigning variables?

Hi guys.. I am trying to figure out the difference between $a=&$b and $a=$b. I know & make the variable to be a reference variable. But the following test gave me the same result. Can anyone explain the difference? Thanks. $a=5; $b=6; $a=&$b; echo $a; //6 $a=5; $b=6; $a=$b; echo $a; //6 ...

Scala multiple assignment to existing variable

I can do something like def f(): Tuple2[String, Long] = ... val (a, b) = f() What about if the variables are already existing? I'm running the same sets of data over filters and I don't want to chain them (long names and such). This is what I tried, but it complains about expecting ; instead of = on the last line: var a = ...initia...

Overloaded assigment operator is not getting called.

I have written a overloaded assignment operator of class perform copying all the variable values. For ex :in Exp.cpp class perform { LOG *ptr; int a; //constructor //destructor perform operator=(const perform & rhs){ ptr = rhs.ptr; a=rhs.s; return * this;} }; In another class output, I have declared a pointer for abc. perform...

Are `=` and `<-` exactly the same in R?

Possible Duplicate: Assignment operators in R: = and <- Is it just a style preference? As far as I can tell, they are the same. I see many people prefer the "longer" <- version and I can't tell why (perhaps keeping away from = and == confusions?) ...

Method parameter assignment in C#

Given the below code, will the method parameter y in Bar(int y) be assigned the value from x or 1? I realize they are logically equivalent, but I want to understand the assignment operation. class Program { static void Main(string[] args) { var foo = new Foo(); var x = 0; foo.Bar(x = 1); } } public ...

Default copy assignment with array members

I've got a class definition similar to the following: class UUID { public: // Using implicit copy assignment operator private: unsigned char buffer[16]; }; I've just had a unit test fail on me that was verifying that copy assignment worked properly. To my surprise, one byte in the middle of the buffer[] array was copied ...

how to use if else in xquery assignment

Hi, I am trying to use a if condition to assign a value to a variable in an xquery. I am not sure how to do this. This is what I tried: declare namespace libx='http://libx.org/xml/libx2'; declare namespace atom='http://www.w3.org/2005/Atom'; declare variable $entry_type as xs:string external; let $libx_node := if ($entry_type = 'p...

Are assignment operators not overloaded, when called upon pointers of a base class?

I have encountered the following problem which proved to me that I know far too little about the workings of C++. I use a base class with pure virtual functions class Base ... and a derived classes of type class Derived : public Base{ private: Foo* f1; ... Both have assignment operators implemented. Among other things, t...

C++ - call assignment operator at creation instead of copy constructor

I want to enforce explicit conversion between structs kind of like native types: int i1; i1 = some_float; // this generates a warning i1 = int(some_float): // this is OK int i3 = some_float; // this generates a warning I thought to use an assignment operator and copy constructor to do the same thing, but the behavior is different: St...

Is there a way to customize/override assignment operations in JavasScript?

Every time I assign a string, I'd actually like to assign a string object, without the extra code. This var foo = "bar"; becomes var foo = new String("bar"); Basically hi-jacking the assignment. Follow-up: If the above is not possible is there a way to prototype the string variable type, rather than the String object? As ...

C++ - overloading assignment operator for default types

Hi, I want to overload the assignment operator for types like "int", "long" etc. That is, I want to use code like: class CX { private: int data; ... }; CX obj; int k; k = obj; // k should get the value of obj.data Apparently assignment operators cannot be friend functions. How do I achieve the above? I maybe missing something ...