Reputation: 111
I'm trying to play around with my new class lesson in Pointer Arguments, and i want to make the functions senior and everyoneElse take pointer x, yet when I try to call the function with the pointer pAge, it says Error: Type name is not allowed. What's wrong?
#include <iostream>
int senior(int* x);
int everyoneElse(int* x);
using namespace std;
int main()
{
int age(0);
int* pAge(&age);
cout<<"How old are you?"<<endl;
cin>>age;
if(age>59)
senior(int* pAge);
else
everyoneElse(int* pAge);
return 0;
}
int senior(int* x)
{
return *x;
}
int everyoneElse(int* x)
{
return *x;
}
Upvotes: 11
Views: 153210
Reputation: 1092
When you call the function, you do not have to specify type of parametr, that you pass to a function:
if(age>59)
senior(pAge);
else
everyoneElse(pAge);
Parametrs should be specified by type only in function prototype and body function (smth like this:)
int senior(int* x)
{
return *x;
}
Upvotes: 4
Reputation: 767
How you are calling the function int senior(int x)* and int everyoneElse(int x)* is wrong call the function as : everyoneElse(pAge) and int senior(x)
see link http://msdn.microsoft.com/en-us/library/be6ftfba(v=vs.80).aspx
Upvotes: 0
Reputation: 9589
if(age>59)
senior(int* pAge);
else
everyoneElse(int* pAge);
You can't include the typename when calling a function. Change to:
if(age>59)
senior(pAge);
else
everyoneElse(pAge);
Upvotes: 15
Reputation: 3047
senior(int* pAge);
else
everyoneElse(int* pAge);
replace with
senior(pAge);
else
everyoneElse(pAge);
Upvotes: 7