我绘制了这段代码以突出显示相关位。编译代码时:
#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行的问题吗?
谢谢!
答案 0 :(得分:3)
new是保留关键字!
LeaseState updated_lease_state(LeaseState current, LeaseState newState)
{
return (newState | (current ^ newState));
}