adarshakb
07-04-2009, 06:11 AM
This my program which works:
#include <iostream.h>
class circle
{
private:
int r;
int x,y;
public:
circle()
{
x=y=r=0;
cout<<"\nNew object created";
showData();
}
circle(int xx,int yy,int rr)
{
x=xx;y=yy;r=rr;
cout<<"\nNew object created";
showData();
}
void showData()
{
cout<<"\n(x.y)="<<x<<","<<y<<" r="<<r;
}
circle& operator=(circle& a)
{
x=a.x;
y=a.y;
r=a.r;
return *this;
}
};
void main()
{
circle x(10,5,5);
circle y(10,10,5);
circle z;
z=x;
x=y;
y=z;
x.showData();
y.showData();
}
NOW.. if i change in the main() function circle z; to
circle z();
then the following error occurs:
Compiling...
circle_thispointer2.cpp
error C2659: '=' : overloaded function as left operand
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class circle (__cdecl *)(void)' (or there is no acceptable conversion)
P.S: THIS IS NOT A HOME WORK..lol
Error executing cl.exe.
Can someone pls explain why it occurs?:mad: and its mechanism:thumbsup:
#include <iostream.h>
class circle
{
private:
int r;
int x,y;
public:
circle()
{
x=y=r=0;
cout<<"\nNew object created";
showData();
}
circle(int xx,int yy,int rr)
{
x=xx;y=yy;r=rr;
cout<<"\nNew object created";
showData();
}
void showData()
{
cout<<"\n(x.y)="<<x<<","<<y<<" r="<<r;
}
circle& operator=(circle& a)
{
x=a.x;
y=a.y;
r=a.r;
return *this;
}
};
void main()
{
circle x(10,5,5);
circle y(10,10,5);
circle z;
z=x;
x=y;
y=z;
x.showData();
y.showData();
}
NOW.. if i change in the main() function circle z; to
circle z();
then the following error occurs:
Compiling...
circle_thispointer2.cpp
error C2659: '=' : overloaded function as left operand
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class circle (__cdecl *)(void)' (or there is no acceptable conversion)
P.S: THIS IS NOT A HOME WORK..lol
Error executing cl.exe.
Can someone pls explain why it occurs?:mad: and its mechanism:thumbsup: