#include <conio.h>
#include <iostream>
using namespace std;
class Test
{
private:
int a;
int *b;
public:
Test();
Test(int x, int y);
void print();
Test(const Test& yourTest); const Test& operator=(const Test& anotherTest); ~Test(); };
Test::Test()
{
a = -69;
b = new int;
*b=0;
}
Test::Test(int x, int y)
{
cout << "Constructor Called .. " << endl;
a = x;
b = new int;
*b = y;
}
void Test::print()
{
cout << "A = " << a << "\t" << "B = " << *b << "\n\n";
}
Test::Test(const Test& yourTest)
{
cout << "Copy Constructor Called .. " << endl;
a = yourTest.a;
b = new int;
*b = *(yourTest.b);
}
const Test& Test::operator=(const Test& anotherTest)
{
cout << "Assignment Operator Called .. " << endl;
if (this != &anotherTest){
a = anotherTest.a;
*b = *(anotherTest.b);
return *this;
}
else
{
cout << "Self Assignment .. " << endl;
return *this;
}
}
Test::~Test(){
delete b;
}
int main()
{
Test T1(2,3);
Test T2(T1);
T1.print();
T2.print();
getch();
return 0;
}