amin.akmali
Member
لطفا برنامه ی کوچکی بنویسید که در آن تعریف مجدد عملگر = را بکار برید.مرسی
لطفا برنامه ی کوچکی بنویسید که در آن تعریف مجدد عملگر = را بکار برید.مرسی
#include <iostream.h>
#include <conio.h>
using namespace std;
class Test
{
public:
int value;
Test()
{
value = 0;
}
Test(int value)
{
this->value = value;
}
[COLOR="Blue"][B] Test& Test::operator=(const Test &t)
{
this->value = t.value;
return *this;
}
[/B][/COLOR]};
int main()
{
Test a(10), b(20);
cout << "a = " << a.value << ", b = " << b.value << endl;
a = b;
b.value = 30;
cout << "a = " << a.value << ", b = " << b.value << endl;
getch();
return 0;
}