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;
}
                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;
}
                        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);
                        senior(int* pAge);
else
    everyoneElse(int* pAge);
replace with
senior(pAge);
else
    everyoneElse(pAge);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With