So, let us say we have the following class:
Why must I put Class& instead of Class as return-type? If I were to have a static variable, which would count my objects, putting the return-type as Class , without &, would increase the count var even though I haven't called any constructor, default, copy, not even one. Yet, it is incremented. Can someone explain?
class Class {
public:
int x;
static int count;
Class& operator=(const Class& c) {
this->x = c.x;
}
};
I have looked for an explanation on the internet, but no good answer has been found. I hope someone on StackOverflow could answer my inquiry.