assignment-operator Questions

1

Solved

Let's just take for example the specific compound assignment operator ^=. This stackoverflow page says modification of the left operand may have not been done after the evaluation of ^=, and thus m...

2

Solved

If we put copy constructor and assign operator as private and provide no implementation, they will be disabled, like this: class Test { private: Test(const Test&); Test& operator=(const ...
Torpid asked 18/3, 2015 at 11:8

1

Solved

If T is a class type with the default signature for assignment operator, then we can write: T const &ref = ( T{} = something ); which creates a dangling reference. However, with the signatu...
Deauville asked 19/2, 2015 at 4:9

6

Solved

Are both these PHP statements doing the same thing?: $o =& $thing; $o = &$thing;
Dennis asked 8/5, 2011 at 20:31

4

Solved

Hope this is not a duplicate. If so, please point me to it in a comment and I'll remove the question again. I have a data object with data that's only valid in a bundle - i.e. there's no sense in ...
Brillatsavarin asked 11/6, 2013 at 13:10

2

Solved

For example: class Foo : public Bar { ~Foo() { // Do some complicated stuff } Foo &operator=(const Foo &rhs) { if (&rhs != this) { ~Foo(); // Is this safe? // Do more stuff...
Conservatism asked 23/1, 2015 at 15:42

1

Solved

I am writing unit tests for a few classes (C++), and came across an issue attempting to write a unit test for the copy constructor and assignment operator. A basic thing that could be wrong with ei...

5

Solved

I have a class B with a set of constructors and an assignment operator. Here it is: class B { public: B(); B(const string& s); B(const B& b) { (*this) = b; } B& operator=(const B...
Wrench asked 4/8, 2009 at 9:58

5

Solved

While playing with implementing a virtual assignment operator I have ended with a funny behavior. It is not a compiler glitch, since g++ 4.1, 4.3 and VS 2005 share the same behavior. Basically, th...
Treadwell asked 9/6, 2009 at 10:20

2

Why is if let y: Int? = nil { ... } the same as if let y: Int? = nil as Int?? { ... } (and thus an invalid assignment) especially when, on its own let y: Int? = nil is not the same as ...
Nympha asked 28/10, 2014 at 18:23

5

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 ...
Bozovich asked 27/7, 2010 at 23:19

5

Solved

In the following code: int c; while((c=10)>0) What does c = 10 evaluate to? Is it 1 which indicates that the value 10 is assigned to variable c successfully, or is it 10? Why?
Clerissa asked 15/5, 2013 at 14:21

1

Solved

I'm currently investigating the interplay between polymorphic types and assignment operations. My main concern is whether or not someone might try assigning the value of a base class to an object o...
Barnard asked 28/8, 2014 at 10:53

2

Solved

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 assignmen...
Bend asked 22/9, 2010 at 14:51

1

Solved

I have the following code snippet: main( ) { int k = 35 ; printf ( "\n%d %d %d", k == 35, k = 50, k > 40 ) ; } which produces the following output 0 50 0 I'm not sure I understand h...

1

A common thing I find myself doing is making "almost default" copy constructors and assignment operators. That is, I find myself in situations where the compiler supplied copy and assignment operat...
Ransell asked 11/7, 2014 at 23:38

3

Solved

Recently I was rereading ISO C++ standard, and found very interesting note: Note that for std::vector, the only constraint on type T of std::vector<T> is that type T must have copy constru...
Sisterhood asked 26/6, 2014 at 8:2

5

Solved

What is the copy-and-swap idiom and when should it be used? What problems does it solve? Does it change for C++11? Related: What are your favorite C++ Coding Style idioms: Copy-swap Copy construct...

2

Solved

The book I'm reading says that when your class contains a member that's a reference or a const, using the compiler-generated copy constructor or assignment operators won't work. For instance, #inc...

2

Solved

I understand that this is undefined behavior: int i = 0; int a[4]; a[i] = i++; //<--- UB here because the order of evaluation of i for the left hand side and the right hand side are undefined (...

3

Solved

i have a c++ class to handle fractions and i want it to allow conversion to double, i have something like that : class fraction { double n,d; public: fraction(double _n, double _d) {n = _n;...
Collaborative asked 4/4, 2014 at 9:59

4

Solved

In an already existing class of a project I am working on I encountered some strange piece of code: The assignment operator calls the copy constructor. I added some code and now the assignment ope...
Ruin asked 27/3, 2014 at 10:41

4

Solved

Ignoring the types of variables, is expression like a=b=c has defined behavior in both C and C++? If so, can any one give me official evidence, like quotes from the standard, please? P.S. I searc...
Matthewmatthews asked 24/3, 2014 at 12:12

4

Solved

I have 2 ArrayLists in Java: mProductList = new ArrayList<ProductSample>(); mProductList2 = new ArrayList<ProductSample>(); mProductList = productSampleList; mProductList2 = product...
Antler asked 13/3, 2014 at 4:27

5

Solved

When overloading assignment operator of a class in C++, must its parameter be reference? For example, class MyClass { public: ... MyClass & operator=(const MyClass &rhs); ... } Can it ...
Goodygoody asked 30/5, 2010 at 22:35

© 2022 - 2024 — McMap. All rights reserved.