#include <iostream>

using namespace std;

class Cow{
public:
    char * name;
    Cow(){cout << "I'm a constructor, making a cow.\n"; name = NULL;};
    Cow(const Cow& other);
    ~Cow(){cout << "I'm the stranger, killing an array.\n"; delete[] name;}
    Cow& operator=(const Cow& other);
};

int main(){
    
    Cow c1;
    c1.name = new char[30];
    strcpy(c1.name,"Feckless");
    Cow c3;
    Cow c2 = c1; //copy constructor
    c3 = c1; //overloaded assignment
    cout << c3.name << endl;
    cout << c2.name << endl;

    return 0;
}

Cow& Cow::operator=(const Cow& other){
    cout << "I'm overloaded assignment.\n"; 
    if (this != &other){ //WHY????
	delete[] name;
	if(other.name){
	    name = new char[1 + strlen(other.name)];
	    strcpy(name, other.name);
	}
    }
}

Cow::Cow(const Cow& other){
    cout << "I'm a copy constructor.\n"; 
    if(other.name){
	name = new char[1 + strlen(other.name)];
	strcpy(name, other.name);
    }
};

//The Big Three
//destructor
//copy constructor
//overloaded assignment

