defining function within class

Hi, I am not sure about why defining a function within a class doesn't take any parameters in the code below. (Please ignore any physical meaning of the area and volume calculations, it's modified from the original code to better show the problem.) In the function "area" for example, it only works if I remove the "width, height" parameters. I'm wondering why I can't put them there. Thanks for helping!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  class Rectangle {
	double width, height;
public:
	Rectangle(double x, double y) : width(x), height(y) {};
	double area(width, height) { return width + height; }
};

class Cylinder {
	Rectangle rec;
	double h;
public:
	Cylinder(double a, double b, double c) : rec(a, b), h(c) {};
	double volume() { return rec.area()*h; }
};

int main() {
	Cylinder foo{ 10, 20, 30 };
	cout << foo.volume() << endl;
	cin.get();
}
Which of these is syntactically correct declaration of a function:
1
2
double area( x, y );
double area( double x, double y );
Topic archived. No new replies allowed.