assignment-operator Questions

2

I have a problem with misleading error messages, when I try to compile the following minimal sample in Visual Studio 2015: class Vector { float x; float y; public: Vector(float x, float y) : x...
Instillation asked 25/11, 2015 at 16:31

10

Solved

As I've understand, when overloading operator=, the return value should should be a non-const reference. A& A::operator=( const A& ) { // check for self-assignment, do assignment return *this;...
Abe asked 15/3, 2010 at 14:8

1

I was looking at someone's library the other day and they had this: internal static string BaseUrl => "https://api.stripe.com/v1"; public static string Invoices => BaseUrl + "/invoices...
Chickpea asked 18/4, 2016 at 22:2

5

Solved

class A, B; class A { public: A& operator= ( const A &rhs ) { return *this; } }; class B: public A { public: B& operator= ( const A &rhs ) { return *this; } }; A a; B b; std::li...
Brigandage asked 16/4, 2016 at 22:38

2

Solved

I've seen a couple of people using [<- as a function with Polish notation, for example x <- matrix(1:4, nrow = 2) `[<-`(x, 1, 2, 7) which returns [,1] [,2] [1,] 1 7 [2,] 2 4 I've t...
Chimp asked 1/2, 2016 at 20:15

2

Solved

Typically, given some type T, to implement copy and move assignment, one needs two functions T& operator=(T&&) { ... } T& operator=(const T&) { ... } Recently, I come to real...
Boles asked 15/1, 2016 at 4:19

8

Solved

What does copying an object mean? What are the copy constructor and the copy assignment operator? When do I need to declare them myself? How can I prevent my objects from being copied?
Tenebrific asked 13/11, 2010 at 13:27

5

Solved

From the boost library documentation I read this: Conceptually, smart pointers are seen as owning the object pointed to, and thus responsible for deletion of the object when it is no longer ne...
Constraint asked 17/12, 2012 at 10:26

5

Solved

Say I want to override the operator = so I can do something like Poly p1; // an object representing a polynomial Poly p2; // another object of the same type p2 = p1; // assigns all the contents o...
Transfusion asked 2/1, 2016 at 5:19

1

Solved

It seems like a std::tuple containing one or more references has unexpected behavior with regards to construction and assignment (especially copy/move construction and copy/move assignment). It's d...
Praxis asked 31/12, 2015 at 7:26

1

The VisualStudio 2013 compiler handles the following code just fine, but clang 5.0 and 6.2 gives me a linker error: #include <memory> using namespace::std; class IBase { public: virtual I...
Reneerenegade asked 22/12, 2015 at 8:38

1

This question is about HISTORY (not your current opinions on the matter). While reading post about dropping support for increment/decrement operators for Swift I read such text "Swift already devi...
Petiolate asked 9/12, 2015 at 7:31

2

Solved

I am reading qt sources and I've seen a code like this many times: buttonOpt.QStyleOption::operator=(*opt); So, I guess it is something like buttonOpt = *opt but why do they use this syntax inst...
Generation asked 9/10, 2015 at 9:12

2

A "Singular Iterator" is defined as an: iterators that are not associated with any sequence. A null pointer, as well as a default-constructed pointer (holding an indeterminate value) is singula...

2

Solved

I have to implement basically the same function but for different size. Specifically it is something like... type& operator=(unsigned int); type& operator=(unsigned long int); type& op...
Cartesian asked 23/9, 2015 at 10:30

2

Solved

Here is an exercise from C++ Primer 5th Edition: Exercise 13.53: As a matter of low-level efficiency, the HasPtr assignment operator is not ideal. Explain why. Implement a copy-assignment an...

4

Solved

Well here is my first post. I've been trying to do this choice choosing thing and I want the user to choose only numbers instead of typing them down (easier) but when I want the numbers to eq...
Dipstick asked 31/8, 2015 at 14:3

3

Solved

How does this code, involving assignment and the yield operator, work? The results are rather confounding. def test1(x): for i in x: _ = yield i yield _ def test2(x): for i in x: _ = yield...
Semiskilled asked 20/8, 2015 at 21:7

1

I know I could do this better with std::vector, but the application I am messing with, has already a bunch of CArray parameters on a lot of related functions ... and I will not change them all at t...
Paley asked 19/8, 2015 at 15:58

1

Solved

Code: #include <valarray> #include <iostream> using namespace std; int main() { valarray<int> v0(2, 4); valarray<int> v1; v1 = v0; cout << "v0.size: " <<...
Tate asked 6/8, 2015 at 22:18

1

I was reading about copy-control and came across the following sample in the book C++ Primer (chapter 13.4). My question is about the remove_from_Folders(); inside copy assignment operator: If w...
Lighter asked 27/3, 2015 at 18:50

9

Solved

The assignment operator can be overloaded using a member function but not a non-member friend function: class Test { int a; public: Test(int x) :a(x) {} friend Test& operator=(Test &o...
Hartsell asked 14/10, 2010 at 13:29

4

Solved

I have to create a function that takes as input a vector v and three scalars a, b and c. The function replaces every element of v that is equal to a with a two element array [b,c]. For example, gi...
Gifford asked 1/5, 2015 at 16:55

1

Solved

In Ruby, we assign values to objects with the = operator. Combine this with implicit typing and we frequently get situations like this: myVar= :asymbol The above line both creates a new symbol...
Maishamaisie asked 20/4, 2015 at 19:19

1

Solved

I have a class in which I want to enable the copy/move assignment operators only if a type parameter to the class is nothrow copy/move constructible respectively. So I tries this: #include <typ...
Bor asked 16/4, 2015 at 23:59

© 2022 - 2024 — McMap. All rights reserved.