KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm doing some revision of my C++, and I'm dealing with operator overloading at the minute, specifically the "="(assignment) operator. I was looking online and came across multiple topics discussing it. In my own notes, I have all my examples taken down as something like class Foo { public: int x; int y; void operator=(const Foo&); }; void Foo::operator=(const Foo &rhs) { x = rhs.x; y = rhs.y; } In all the references I found online, I noticed that the operator returns a reference to the source object. Why is the correct way to return a reference to the object as opposed to the nothing at all?
Tags (comma-separated)
Save Edits
Cancel