随笔 - 20, 文章 - 0, 评论 - 5, 引用 - 0
数据加载中……

C++运算符优先级

http://www.cppreference.com/wiki/operator_precedence 
小结:不能重载运算符 ::    .    .*      ? :   
PrecedenceOperatorDescriptionExampleOverloadableAssociativity
1::Scope resolution operatorClass::age = 2;noleft to right
2()Function callprintf(“Hello world\n”);yesleft to right
()Member initalizationc_tor(int x, int y) : _x(x), _y(y * 10) {}yes
[]Array accessarray[4] = 2;yes
->Member access from a pointerptr->age = 34;yes
.Member access from an objectobj.age = 34;no
++Post-incrementfor (int i = 0; i < 10; i++) cout << i;yes
--Post-decrementfor (int i = 10; i > 0; i--) cout << i;yes
dynamic_castRuntime-checked type conversionY& y = dynamic_cast<Y&>(x);no
static_castUnchecked type conversionY& y = static_cast<Y&>(x);no
reinterpret_castReinterpreting type conversionint const* p = reinterpret_cast<int const*>(0x1234);no
const_castCast away/Add constnessint* q = const_cast<int*>(p);no
typeidGet type informationstd::type_info const& t = typeid(x);no
3!Logical negationif (!done) ...yesright to left
notAlternate spelling for !
~Bitwise complementflags = ~flags;yes
complAlternate spelling for ~
++Pre-incrementfor (i = 0; i < 10; ++i) cout << i;yes
--Pre-decrementfor (i = 10; i > 0; --i) cout << i;yes
-Unary minusint i = -1;yes
+Unary plusint i = +1;yes
*Dereferenceint data = *intPtr;yes
&Address ofint *intPtr = &data;yes
sizeofSize (of the type) of the operand in bytessize_t s = sizeof(int);no
newDynamic memory allocationlong* pVar = new long;yes
new []Dynamic memory allocation of arraylong* array = new long[20];yes
deleteDeallocating the memorydelete pVar;yes
delete []Deallocating the memory of arraydelete [] array;yes
(type)Cast to a given typeint i = (int)floatNum;yes
4->*Member pointer selectorptr->*var = 24;yesleft to right
.*Member object selectorobj.*var = 24;no
5*Multiplicationint i = 2 * 4;yesleft to right
/Divisionfloat f = 10.0 / 3.0;yes
%Modulusint rem = 4 % 3;yes
6+Additionint i = 2 + 3;yesleft to right
-Subtractionint i = 5 - 1;yes
7<<Bitwise shift leftint flags = 33 << 1;yesleft to right
>>Bitwise shift rightint flags = 33 >> 1;yes
8<Comparison less-thanif (i < 42) ...yesleft to right
<=Comparison less-than-or-equal-toif (i <= 42) ...yes
>Comparison greater-thanif (i > 42) ...yes
>=Comparison greater-than-or-equal-toif (i >= 42) ...yes
9==Comparison equal-toif (i == 42) ...yesleft to right
eqAlternate spelling for ==
!=Comparison not-equal-toif (i != 42) ...yes
not_eqAlternate spelling for !=
10&Bitwise ANDflags = flags & 42;yesleft to right
bitandAlternate spelling for &
11^Bitwise exclusive OR (XOR)flags = flags ^ 42;yesleft to right
xorAlternate spelling for ^
12|Bitwise inclusive (normal) ORflags = flags | 42;yesleft to right
bitorAlternate spelling for |
13&&Logical ANDif (conditionA && conditionB) ...yesleft to right
andAlternate spelling for &&
14||Logical ORif (conditionA || conditionB) ...yesleft to right
orAlternate spelling for ||
15? :Ternary conditional (if-then-else)int i = a > b ? a : b;noright to left
16=Assignment operatorint a = b;yesright to left
+=Increment and assigna += 3;yes
-=Decrement and assignb -= 4;yes
*=Multiply and assigna *= 5;yes
/=Divide and assigna /= 2;yes
%=Modulo and assigna %= 3;yes
&=Bitwise AND and assignflags &= new_flags;yes
and_eqAlternate spelling for &=
^=Bitwise exclusive or (XOR) and assignflags ^= new_flags;yes
xor_eqAlternate spelling for ^=
|=Bitwise normal OR and assignflags |= new_flags;yes
or_eqAlternate spelling for |=
<<=Bitwise shift left and assignflags <<= 2;yes
>>=Bitwise shift right and assignflags >>= 2;yes
17throwthrow exceptionthrow EClass(“Message”);no
18,Sequential evaluation operatorfor (i = 0, j = 0; i < 10; i++, j++) ...yesleft to right

posted on 2010-09-03 18:19 Eping 阅读(276) 评论(0)  编辑 收藏 引用 所属分类: C++基础


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理