Question: I made the following operator overloading test:

```
#include <iostream>
#include <string>

using namespace std;

class TestClass
{
    string ClassName;

    public:

    TestClass(string Name)
    {
        ClassName = Name;
        cout << ClassName << " constructed." << endl;
    }

    ~TestClass()
    {
        cout << ClassName << " destructed." << endl;
    }

    void operator=(TestClass Other)
    {
        cout << ClassName << " in operator=" << endl;
        cout << "The address of the other class is " << &Other << "." << endl;
    }
};

int main()
{
    TestClass FirstInstance("FirstInstance");
    TestClass SecondInstance("SecondInstance");

    FirstInstance = SecondInstance;
    SecondInstance = FirstInstance;

    return 0;
}

```

The assignment operator behaves as-expected, outputting the address of the other instance.

Now, how would I actually *assign* something from the other instance? For example, something like this:

```
void operator=(TestClass Other)
{
    ClassName = Other.ClassName;
}

```

Answer: 
Traditionnaly the assignment operator and the copy constructor are defined passing a const reference, and not with a copy by value mechanism.

```
class TestClass 
{
public:
    //... 
    TestClass& operator=(const TestClass& Other)
    {
        m_ClassName= Other.m_ClassName;
        return *this;
    }
private:
    std::string m_ClassName;
 }

```

EDIT: I corrected because I had put code that didnt return the TestClass& (c.f. @sbi 's answer)
You are correct about how to copy the contents from the other class. Simple objects can just be assigned using `operator=`.

However, be wary of cases where `TestClass` contains pointer members -- if you just assign the pointer using `operator=`, then both objects will have pointers pointing to the same memory, which may not be what you want. You may instead need to make sure you allocate some new memory and copy the pointed-to data into it so both objects have their own copy of the data. Remember you also need to properly deallocate the memory already pointed to by the assigned-to object before allocating a new block for the copied data.

By the way, you should probably declare your `operator=` like this:

```
TestClass & operator=(const TestClass & Other)
{
    ClassName = Other.ClassName;
    return *this;
}

```

This is the general convention used when overloading `operator=`. The return statement allows chaining of assignments (like `a = b = c`) and passing the parameter by `const` reference avoids copying `Other` on its way into the function call.