Linked Questions

11 votes
2 answers
10k views

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 ...
JoeBass's user avatar
  • 569
1 vote
3 answers
163 views

iarray<T>& operator = (iarray<T>& v) Why the return type is iarray<T>& not iarray<T> ? UPDATE Can someone elaborate in great detail why iarray<T> const &...
Alan's user avatar
  • 5,269
1 vote
1 answer
110 views

I have written a class in C++ and have defined assignment operator function: cplusplus.com recommends following syntax. check operator= (const check& obj){*cstr = *(obj.cstr); return *this;} One ...
Ashish Paliwal's user avatar
-2 votes
2 answers
195 views

To pass user-defined datatypes into SystemC channels templates requires these datatypes to be defined as a class that implements also different kind of operators <<, =, ==. I need to define a ...
Theo's user avatar
  • 41
0 votes
0 answers
110 views

I am currently studying "Object-oriented design choices" by Dingle (2021), a required textbook for my Object-Oriented Design Class. While going through the chapter on "Move Semantics,&...
i_hate_F_sharp's user avatar
0 votes
0 answers
42 views

I've been brushing up on C++ in preparation for a class, and something that's stumped me is returning a reference vs. returning a value (also vs. returning a const reference, but that's not really ...
dylosaur's user avatar
  • 149
2419 votes
5 answers
536k views

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 constructor ...
GManNickG's user avatar
  • 506k
5 votes
3 answers
2k views

I read about this from "Effective c++" ,this is Col.10. It say it's a good way to have assignment operators return a reference to *this. I wrote a code snippet to test this idea. I overridden the ...
Don Lun's user avatar
  • 2,777
5 votes
2 answers
14k views

I've seen many tutorials and tried to find the answer on stackoverflow but with no success. What I'm not sure of is; is there some praxis when to return by value or by reference, when overloading an ...
Johnnie W's user avatar
  • 127
4 votes
4 answers
473 views

I went over making my own copy constructor and it overall makes sense to me. However, on the topic of doing your own assignment operator I need someone to fill in the blank for me. I pretty much don'...
Ilya's user avatar
  • 1,233
0 votes
3 answers
895 views

I have a problem with my program in c++. I try to write copy constructor. Everything is good until I start copying elements from array from object that is applied as a reference. I can print every ...
user3061714's user avatar
1 vote
4 answers
163 views

I have written following class which has overloaded assignment operator. As shown in example everywhere I returned *this from assignment operator. class Sample { int *p; int q; public: ...
Pranit Kothari's user avatar
2 votes
0 answers
430 views

I am having trouble finding a way to enable the assignment operator to do multiple assignments. given that there is item A,B,C; for(int i=0; i<10; i++) C.AddHead(i); A = B = C; for a single ...
Op-Zyra's user avatar
  • 45