Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Error: Type Name is Not Allowed

Tags:

c++

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;
}
like image 255
user2098000 Avatar asked Feb 22 '13 04:02

user2098000


3 Answers

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;
}
like image 91
Anton Kizema Avatar answered Oct 16 '22 14:10

Anton Kizema


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);
like image 44
Josh Petitt Avatar answered Oct 16 '22 15:10

Josh Petitt


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

replace with

senior(pAge);
else
    everyoneElse(pAge);
like image 7
Boyko Perfanov Avatar answered Oct 16 '22 14:10

Boyko Perfanov