Hello all
I have a head basher, since I think the solution is very easy and obvious but I simply can't find the error. Here is my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
class Point{
int x, y, z;
public:
Point();
Point(int , int , int );
void SetArea(int, int, int);
void ShowArea(void);
};
Point::Point(){
cout << "this is a default counstructor" << endl;
}
Point::Point(int a = 1, int b = 1, int c = 1){
x = a;
y = b;
z = c;
cout << "this is our constructor, and the values are: " << endl;
cout << "x = " << x << "\ny = " << y << "\nz = " << z << endl;
}
class CRectangle {
int width, height;
public:
CRectangle ();
CRectangle (int,int);
int area (void) {return (width*height);}
};
CRectangle::CRectangle () {
width = 5;
height = 5;
}
CRectangle::CRectangle (int a, int b) {
width = a;
height = b;
}
int _tmain(int argc, _TCHAR* argv[]){
funct();
return 0;
}
void funct(void){
CRectangle rect (3,4);
CRectangle rectb;
cout << "rect area: " << rect.area() << endl;
cout << "rectb area: " << rectb.area() << endl;
getchar();
Point myPoint(3,4);
Point hisPoint;
cout << "function \"funct\" finished succesfully" << endl;
getchar();
exit(0);
}
|
This is the code, now onto the problem, as you can see, or as far as I can see, classes Point and CRectangle are very simmiliar as far as counstructors go, they both have 2 of them, so they're obviously overloaded, but what bogles my mind is the error I get when compiling:
"error C2668: 'Point::Point' : ambiguous call to overloaded function"
"could be 'Point::Point(int,int,int)"
"or 'Point::Point(void)"
the error is with this line
Point hisPoint;
which to me seems not all that different from
CRectangle rectb;
I know what the error is sopouse to mean, basically that the compiler doesn't know which function to call, and that I need to specify it more clearly with the arguments,
But I don't see how the CRectangle works then, since I can not find any differences and, he works like a charm.
Hopefully I was at least somewhat clear as to my problem,
any help would be appreciated.
Thanks guys.