C++ 错误:不允许类型名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15016787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 18:53:53  来源:igfitidea点击:

C++ Error: Type Name is Not Allowed

c++

提问by user2098000

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?

我正在尝试使用指针参数中的新课程,我想让函数更高级,而everyoneElse 使用指针 x,但是当我尝试使用指针 pAge 调用该函数时,它说错误:类型名称是不允许。怎么了?

#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;
}

回答by Josh Petitt

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);

回答by Boyko Perfanov

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

replace with

用。。。来代替

senior(pAge);
else
    everyoneElse(pAge);

回答by Anton Kizema

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;
}

回答by Astro - Amit

How you are calling the function int senior(intx)* and int everyoneElse(intx)* is wrong call the function as : everyoneElse(pAge)and int senior(x)

你如何调用函数int Senior(intx)* 和inteveryoneElse (intx)* 是错误的调用函数为:everyoneElse(pAge)int Senior(x)

see link http://msdn.microsoft.com/en-us/library/be6ftfba(v=vs.80).aspx

见链接 http://msdn.microsoft.com/en-us/library/be6ftfba(v=vs.80).aspx