user2098000
user2098000

Reputation: 111

C++ Error: Type Name is Not Allowed

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

Answers (4)

Anton Kizema
Anton Kizema

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

Astro - Amit
Astro - Amit

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

Josh Petitt
Josh Petitt

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

Boyko Perfanov
Boyko Perfanov

Reputation: 3047

senior(int* pAge);
else
    everyoneElse(int* pAge);

replace with

senior(pAge);
else
    everyoneElse(pAge);

Upvotes: 7

Related Questions