argument of type `int (CaloCell::)()' does not match `int'

Jan 17, 2010 at 3:08am
Hey guys,

Pls help, I'm trying to compile the following program:

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
#ifndef CALOCELL_HH
#define CALOCELL_HH



class CaloCell
{
	private:
		double e;
		int i;
		//CaloCell calocell;
	public:

		CaloCell(double energy, int ID) : e(getValenergy), i(getValid) {};
		
		
		double getValenergy() const { return e;}
		
		
		void setValenergy(double newenergy) { e = newenergy;}
		
		int getValid() const { return i;}
		
		
		void setValid(int newid) { i = newid;}


};

#endif 



and the main program is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include "calocell.hh"

using std::cout;
using std::endl;

int main()
{
CaloCell c(2.2,2);
//c.CaloCell (2.2,2);
cout << "energy:" ;
c.getValenergy(); 
cout << endl << endl ;
return 0;
}


I'm getting the following as error message:



In file included from main.cc:2:
calocell.hh: In constructor `CaloCell::CaloCell(double, int)':
calocell.hh:7: error: argument of type `int (CaloCell::)()' does not match `int'


Could anyone pls tell me what is going wrong here?
Thanks
Jan 17, 2010 at 3:13am
What the hell is going on in that constructor?
You're using your class's get functions to initialize variables that have not yet been initialized so you are doomed to get some kind of undefined behavior. Not to mention that those are functions and not objects/variables so you are missing the call operator.
Your constructor should look like this
CaloCell(double energy, int ID) : e(energy), i(ID) {};
Jan 17, 2010 at 3:30am
hey thanks a ton...
kinda new to this thing, so got a little confused with all the initializing!
the program works fine now ! :)
Jan 17, 2010 at 3:31am
...and the semicolon should not follow the body of the constructor.
Topic archived. No new replies allowed.