2017-07-25 118 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; 
} 
相關問題