#include <stdio.h>
class R
{
public:
int k, depth;
R() :k(0), depth(0) {}
const R& operator=( const R & r )
{
if( this != &r )
{
k = r.k;
depth = r.depth+1;
}
return r;
}
};
int main()
{
R r1, r2, r3;
r1 = r2 = r3;
printf( "%d %d %d\n",
r1.depth, r2.depth, r3.depth );
}
I don't get what the method const R& operator=( const R & r ) is doing. From it's signature to what it is doing. Is this operator overloading? What is it trying to do? What is the output of this? I admit that I haven't done C++ in a while.