Rule Of Three for a Coordinate class I just recently got back into C++ and did a quick and simple exercise in the Rule of Three. The code for the copy constructor, overloaded assignment operator, and destructor follows below for my class (code is also below), and I was wondering if someone could take a quick look at it and point out anything that I overlooked.

class Coordinate
{
    private:
        int x;
        int y;
        string *name;

    public:
        Coordinate(int X, int Y, string Name)
        {
            this-&gt;x=X;
            this-&gt;y=Y;
            *(this-&gt;name)=Name;
        }

        //COPY CONSTRUCTOR
        Coordinate(const Coordinate&amp; source)
        {
            this-&gt;x=source.x;
            this-&gt;y=source.y;
            this-&gt;name=new string(*(source-&gt;name));
        }

        //OVERLOADED ASSIGNMENT OPERATOR
        Coordinate&amp; operator= (const Coordinate&amp; source)
        {
            //check for self-assignment aka Coordinate1=Coordinate1
            if(this==&amp;source)
            {
                return *this;
            }

            this-&gt;x=source.x;
            this-&gt;y=source.y;
            this-&gt;name=*(source-&gt;name);

            return *this;
        }

        //DESTRUCTOR
        ~Coordinate()
        {
            delete name;
        }

        void setX(int X)
        {
            this-&gt;x=X;
        }

        void setY(int Y)
        {
            this-&gt;y=Y;
        }

        void setName(string Name)
        {
            *(this-&gt;name)=Name;
        }

        const int getXValue()
        {
            return this-&gt;x;
        }

        const int getYValue()
        {
            return this-&gt;y;
        }

        const string getName()
        {
            return *(this-&gt;name);
        }
};


This post corrects some errors that led to my previous question to be rejected.  I realize that I should have included all the code for my class from the beginning.
This unfortunately shows a rather erroneous understanding of the rule of three. Yes, all three methods are present, but they do not serve their expected purposes. 


Your copy constructor doesn't free the old name before assigning the new one. That's a memory leak. 
Your copy constructor dereferences an unitialized pointer. That's undefined behavior (almost certainly a segfault in this case).
Your assignment operator makes a shallow copy. Not only is it unintuitive to consumers since objects may affect each other, the destructors would attempt to double free the same object likely resulting in a segfault.


Provided the other two were fixed, your destructor is actually correct.

This code may technically compile, and it may even execute, but I would suggest that you run it through something like valgrind before continuing much farther. In addition, it might help to read more about the Rule of 3, learn about the copy and swap idiom, and learn about the Rule of 0, or more generally RAII and idiomatic resource management.



From a design/style perspective:


This isn't a Coordinate. It's a coordinate with a name, perhaps a NamedCoordinate. I would expect the x,y to be encapsulated in some kind of struct in real code and then a NamedCoordinate to contain an instance of that.
Arguments that are not modified should be taken by const reference rather than value. For example, void setName(string Name) makes an unnecessary copy of Name. This gets a bit more complicated in C++11, I'm afraid as your taking parameters by value would be correct, but you would missing std::move calls. Anyway, for C++ &lt; 11, you just need to know that non-modified parameters should be taken by const reference.
using namespace std; is a bad habit
It's customary to leave off this unless it must be included in function calls or member accesses.
snake_case and camelCase are the standards for argument/parameter/member/etc names with either snake_case or PascalCase for classes. Your class name is good, but some of your uppercased parameter names are rather unusual.