...

View Full Version : Resolved ERROR in program.... i cant understand



adarshakb
07-04-2009, 07: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:

oesxyl
07-04-2009, 07:22 AM
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)
Error executing cl.exe.

Can someone pls explain why it occurs?:mad: and its mechanism:thumbsup:
z() is function, z is variable. is a syntax problem.

best regards

adarshakb
07-04-2009, 07:25 AM
a variable and function diference.... and i didnt know that.. thks..
another question :confused:

Then why does the compiler give error about the overloaded operator??

oesxyl
07-04-2009, 07:29 AM
a variable and function diference.... and i didnt know that.. thks..
another question :confused:

Then why does the compiler give error about the overloaded operator??
compiler try to guess what was wrong and jump to conclusion that you intend to overload the () operator but it fail to find the declaration, :)

best regards

adarshakb
07-04-2009, 07:33 AM
compiler try to guess what was wrong and jump to conclusion that you intend to overload the () operator but it fail to find the declaration, :)

best regards

:D:thumbsup:

oesxyl
07-04-2009, 07:45 AM
:D:thumbsup:
:)

is oftopic but I would prefere to implement circle constructor like this:


circle::circle(int ax = 0, int ay = 0, int ar = 0){
x= ax; y=ay; r=ar;
// other things...
}


best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum