2017-03-22 20 views
0

このサンプルコードを作成して関連ビットを強調表示しました。コードがコンパイルされている場合:C++:コンパイルエラーを理解できません

#include <iostream> 

using namespace std; 

enum LeaseState { 
LEASE_NONE     = 0x00, 
LEASE_READ_CACHING   = 0x01, 
LEASE_HANDLE_CACHING   = 0x02, 
LEASE_WRITE_CACHING   = 0x04, 
LEASE_RH_CACHING    = LEASE_READ_CACHING | LEASE_HANDLE_CACHING, 
LEASE_RW_CACHING    = LEASE_READ_CACHING | LEASE_WRITE_CACHING, 
LEASE_RWH_CACHING   = LEASE_READ_CACHING | LEASE_WRITE_CACHING | 
           LEASE_HANDLE_CACHING 
}; 

LeaseState 
updated_lease_state(LeaseState current, LeaseState new) 
{ 
    return (new | (current^new)); 
} 

int main() 
{ 
    cout << "Updated lease state: " << updated_lease_state(LEASE_RW_CACHING, LEASE_READ_CACHING); 
    cout << "\n"; 

    return 0; 
} 

...これは見誤りです:

$ g++ enum.cc 
enum.cc:17: error: expected ‘,’ or ‘...’ before ‘new’ 
enum.cc: In function ‘LeaseState updated_lease_state(LeaseState, LeaseState)’: 
enum.cc:19: error: expected type-specifier before ‘|’ token 
enum.cc:19: error: expected type-specifier before ‘)’ token 

誰かが私にはライン17と間違っているものを理解を助けることはできますか?

ありがとうございます!

+4

'new'はC++の予約語です.SOの強調表示からも分かります。変数名を変更してください –

+0

@SamKuhmonen:ありがとう!その1つを完全に逃した – Maddy

答えて

3

新しいものは予約語です!

LeaseState updated_lease_state(LeaseState current, LeaseState newState) 
{ 
    return (newState | (current^newState)); 
} 
関連する問題