Reputation: 1511
I'm not sure what I've done wrong in my project. I have two files, an airports.h header file and a main source file. In the main source file I have
string code,name;
int deptax, conntime;
cin >> code >> name >> deptax >> conntime;
Airport myAirport(code,name,deptax,conntime);
cout << myAirport.getCode << endl;
and in the airports.h header file I have
class Airport{
public:
Airport(string code, string name, int departureTax, int connectionTime)
:code(code),
name(name),
departureTax(departureTax),
connectionTime(connectionTime)
{...}
string getCode(){
return code;
}//then getName, getDepTax, getConnTime...
}
When I run the main source file, I get the error "error C3867: 'Airport::getCode': function call missing argument list; use '&Airport::getCode' to create a pointer to member" which is in line 5 up there.
I'm a beginner so I'm not sure why it's telling me to do this. Shouldn't .getCode() work how it's written? When I looked for previous solutions to this online, the solution was always something that was unrelated to the "pointer to member" error, so I think I may simply be using c++ in a way that it's not meant to be used.
Upvotes: 0
Views: 79
Reputation: 1516
cout << myAirport.getCode() << endl;
Note the parenthesis needed to call the function. The reason for requiring the () to be there is that a function named without them actually has a valid meaning and it is quite different to calling the function.
Upvotes: 3
Reputation: 420
You're missing the () in the
cout << myAirport.getCode << endl;
after getCode ,should be getCode()
Upvotes: 1
Reputation: 117876
You need to call your function
myAirport.getCode()
instead of
myAirport.getCode
Upvotes: 1