class Rectangle {
int width, height;
public:
Rectangle ();
Rectangle (int,int);
int area (void) {return (width*height);}
};
1.In line 6, there is int area (void) ....
So, the question is what is the function of having void inside int area?
What is the difference with int area () {return (width*height);}
2.Is there any difference between {return w*h;} and {return (w*h);}
If yes please explain it...
For number 3 :
1 2
Rectangle rectb; // ok, default constructor called
Rectangle rectc(); // oops, default constructor NOT called
1. No difference, it just means the function does not accept arguments. It has never been a requirement for C++ to specify void there, but it was in C.
2. No difference. Parentheses are extraneous there.
3. The constructor that takes no arguments.
The problem with this part:
Rectangle rectc(); // <--- a function declaration named rectc, which returns a Rectangle type