calling assignment from copier (UBS IV

#include
// Using “this” in contructor? See http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.7
using namespace std;
struct CAT {
    string name;
    int age;
    CAT& operator=(CAT const & rhs) {
        cout << "entering operator= " << this << " <– " << &rhs << "\n";
        this->name = rhs.name;
        this->age = rhs.age;
        return *this;
    }
    CAT(CAT const & rhs) {
        cout <name << " is current name\n";
        cout <age << " is current age\n";
        *this = rhs; // using operator=
    }
    CAT() {}
};
int main() {
    CAT e;
    e.name = “Thomas “;
    e.age = 33;
    CAT copy(e);
    cout << copy.name << copy.age << endl;
    cin.get();
    return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s