assignment-operator Questions

2

Solved

My question is about parsing expressions in R language. Let me jump right into an example: fun_text <- c(" 0 -> var f1 <- function() { 0 -> sum_var sum_var2 = 0 sum_var3 <- 0 } ...
Acoustic asked 26/4, 2014 at 10:38

7

Solved

Consider the following code: struct s { const int id; s(int _id): id(_id) {} }; // ... vector<s> v; v.push_back(s(1)); I get a compiler error that 'const int id' cannot use default as...
Penury asked 22/7, 2012 at 16:30

1

Solved

Why is that undefined behaviour? struct s { const int id; // <-- const member s(int id): id(id) {} s& operator =(const s& m) { return *new(this) s(m); // <-- undefined behavi...
Davinadavine asked 24/11, 2017 at 12:45

2

Solved

Is there a way to make my new Class mimic the behavior of an int or any Valuetype? I want something, so these assignments are valid MyClass myClass = 1; int i = myClass; var x = myClass; // And h...
Oberhausen asked 15/11, 2017 at 15:37

3

I am looking at the code from here which has this at the beginning: ## generate data for medical example clinical.trial <- data.frame(patient = 1:100, age = rnorm(100, mean = 60, sd = 6), t...
Outsole asked 14/6, 2017 at 12:13

1

Solved

If I have a vector<bool> vec_bool then I cannot modify the contents of the vector using the |= assignment operator. That is, the lines vec_bool[0] |= true; vec_bool[0] |= vec_bool[1]; give...
Alvarez asked 3/10, 2017 at 9:47

3

Solved

Here is an extract from item 56 of the book "C++ Gotchas": It's not uncommon to see a simple initialization of a Y object written any of three different ways, as if they were equivalent. Y ...
Snapp asked 17/3, 2010 at 14:0

2

Solved

Is std::map copy assignment (in style map1 = map2;) required to copy comparator of map2 to map1? I have tested that actual implementations do that. I am more interested about where in C++ standard...
Motet asked 20/7, 2017 at 14:58

3

Solved

I'm a bit lost in C++ operators. I'd like to enforce the assignment operator for two different classes, i.e. so one can assign one to each other: class A { public: virtual A &operator =(const...
Lait asked 6/7, 2017 at 7:53

3

If I say let 5 = 10, why does 5 + 1 return 6 instead of 11?

4

Solved

In Herb Sutter's book Exceptional C++ (1999), he has words in item 10's solution: "Exception-unsafe" and "poor design" go hand in hand. If a piece of code isn't exception-safe, that's generally ...
Embellish asked 18/8, 2012 at 1:47

2

So I have an existing library that provides a string type. It implicitly converts to-from C style strings like so: struct TypeIDoNotOwn { TypeIDoNotOwn() {} TypeIDoNotOwn(TypeIDoNotOwn const&am...
Renovate asked 20/4, 2017 at 14:20

2

Solved

I would like to modify a data.table within a function. If I use the := feature within the function, the result is only printed for the second call. Look at the following illustration: library(d...
Choking asked 7/10, 2015 at 9:5

1

Solved

There are lots of operations in std::ops, but there is nothing for a simple assignment. I'm coming from a C++ background, where there are copy constructor and assignment operator overloading that ...
Modesta asked 22/5, 2016 at 17:15

2

Solved

Some of the assignment overloading operator examples I see online look like this: #include <iostream> using namespace std; class Distance { private: int feet; // 0 to infinite int ...
Cyrillic asked 20/2, 2017 at 1:42

3

Solved

I agree with the consensus that it's generally best to initialise C++ data members in a member initialization list rather than the body of a constructor, but I am sceptical of this explanation T...

3

Solved

In c++ 11, we could disable copy constructor and assignment operator, with delete: class A { A(const A&) = delete; A& operator=(const A&) = delete; } One day, my colleague use the...
Reconcilable asked 3/2, 2017 at 10:4

1

Solved

I was wondering if there was a difference between =+ and += (and other assignment operators too). I tried and both did the same thing. So is there a difference or is there a convention? Do bo...
Mourning asked 12/1, 2017 at 15:6

3

Solved

As explained in this answer, the copy-and-swap idiom is implemented as follows: class MyClass { private: BigClass data; UnmovableClass *dataPtr; public: MyClass() : data(), dataPtr(new Unmova...

2

Solved

I want to assign one class object to another class object in c++. Ex: There is one class Dog and another class Cat. Create one one instance of each (d1 & c1). Don't want to use any STL. I want...
Risibility asked 17/9, 2016 at 15:39

5

Solved

According to ISO C11 - 6.5.16.3, it says that An assignment operator stores a value in the object designated by the left operand. An assignment expression has the value of the left operand a...
Besot asked 20/8, 2016 at 7:9

1

Solved

Prior to C++11, it has always been the case that copy assignment operator should always pass by const reference, like so: template <typename T> ArrayStack<T>& operator= (const Arra...
Tusche asked 6/8, 2016 at 20:38

2

Solved

For a struct with const members struct point { const int x; const int y; }; that is used as member data struct Foo { point pt{ 0, 0 }; void move_x(int value); }; How can Foo::move_x() be wr...
Turnspit asked 8/7, 2016 at 12:41

1

Solved

I only just noticed that this is valid PowerShell code: PS> $first, $rest = @(1, 2, 3) This statement puts the first item in the array in $first and the remaining items in $rest. PS> $fir...

3

Solved

I need to disable the copy assignment operator. This will work: A& operator=(const A&); Will it work if I don't specify exact parameters for operator=? I mean something like this: void ...
Stodgy asked 29/5, 2016 at 8:16

© 2022 - 2024 — McMap. All rights reserved.