Compiling error - out of scope

I have just started learning C++. I get this error while trying to compile the code attached. I have tried several ways but no success, thanks in advance!

home/jordi/Desktop/cplusplus_tutorials/main.cc: In function ‘int main()’:
/home/jordi/Desktop/cplusplus_tutorials/main.cc:57:17: error: ‘r’ was not declared in this scope
vol=getVolume(r,h);
^
/home/jordi/Desktop/cplusplus_tutorials/main.cc:57:19: error: ‘h’ was not declared in this scope
vol=getVolume(r,h);
^
/home/jordi/Desktop/cplusplus_tutorials/main.cc:57:7: error: ‘getVolume’ was not declared in this scope
vol=getVolume(r,h);
^~~~~~~~~
/home/jordi/Desktop/cplusplus_tutorials/main.cc:57:7: note: suggested alternative: ‘getline’
vol=getVolume(r,h);
^~~~~~~~~
getline
make[2]: *** [CMakeFiles/main.dir/build.make:63: CMakeFiles/main.dir/main.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:84: all] Error 2


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
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>

using namespace std;

class cilinder
{
public:
	double r; //this is the radii of the circular base of the cilinder
	double h; //this is the height of the cilinder

	//Member function definition
	double getVolume(){
		return M_PI*pow(r,2)*h;
	}
};
	int main()	{
		cilinder cil1;
		cil1.r=3;
		cil1.h=5;
		double vol;
		vol=getVolume(r,h);
		cout << "The volume is" << vol << endl;
		return 0;
	}
You forgot cil1 in front of getVolume(). Further more getVolume() does not take parameters. You already set r,h on line 20/21.

vol=cil1.getVolume(r,h);
Thank you very much for your time @coder777, issue solved! :D
Topic archived. No new replies allowed.