A simple copy and assignment operator example

#include<iostream>
#include<stdio.h>

using namespace std;

class Test
{
public:
Test() {}
Test(const Test &t)
{
cout<<“Copy constructor called “<<endl;
}
Test& operator = (const Test &t)
{
cout<<“Assignment operator called “<<endl;
}
};

int main()
{
Test t1, t2;
t2 = t1; //assignemt operator
Test t3 = t1; //copy operator
getchar();
return 0;
}

Advertisements