2017-07-25 119 views
-1

我不知道为什么会出现这个错误,我找不出它为什么显示出来。有人请帮忙!在'not'令牌之前预期的非限定标识C++

#include <iostream> 

using namespace std; 

int not(int x){ 
    cout << Enter your number; 
    cin >> x; 
    if(x==1){ 
    return 1; 
    } 
    else{ 
    return x * (x-1); 
    } 
} 

int main(5) 
{ 
    cout << not(); 
} 

编辑:如果有帮助,错误是在第5行。

+1

'INT主(5)'?错字? –

+3

'cout << not();''not' should be called with argument。 – Ari0nhh

+0

@ Ari0nhh,比这更糟糕。看Nicky的回答。 –

回答

9

not替代权标。它被用作运营商!的替代拼写。它不能用作函数名称。

虽然替代令牌在技术上不是保留关键字,但这两种类型不能用作名称。

参见:

+0

其实'not'不是关键字。这是一个所谓的多图,由预处理器用'!'代替。结果是,你可以通过'int bitand ref = val;'等来表示引用。 –

+0

@HenriMenke让我想一种方法来编辑答案的正确性,而不会过分注意技术性。 –

1

令牌 '不' 是C++保留的关键字之一。你不能用'不'来命名一个函数。

更重要的是,您的代码中还存在其他一些错误,例如函数调用未命中参数。下面的代码将是你想要的,我想。

#include <iostream> 

using namespace std; 

int not_func(int x){ 
    cout << "Enter your number"; 
    cin >> x; 
    if(x==1){ 
    return 1; 
    } 
    else{ 
    return x * (x-1); 
    } 
} 

int main() 
{ 
    cout << not_func(5); 
} 
0

标记'not'是C++保留的关键字之一。你不能用'不'来命名一个函数。 也....我觉得没有必要通过从主任何事情,因为你虽然功能进入它。(不能使用代码)

#include <iostream.h> 
using namespace std; 
int nott(int x){ 
    cout <<"Enter your number"; 
    cin >> x; 
    if(x==1){ 
    return 1; 
    } 
    else{ 
    return x * (x-1); 
    } 
} 
int main(){//no need to pass any thing 
    int x;  
    x=nott(5); 
    cout<<x; 
} 
相关问题