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: 
almost all said, a few notes:

* check for self-assignment, i.e. `if (&other != this) // assign`
* look here for an excellent guide on [operator overloading](http://www.cs.caltech.edu/courses/cs11/material/cpp/donnie/cpp-ops.html)
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)