• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            woaidongmao

            文章均收錄自他人博客,但不喜標(biāo)題前加-[轉(zhuǎn)貼],因其丑陋,見(jiàn)諒!~
            隨筆 - 1469, 文章 - 0, 評(píng)論 - 661, 引用 - 0
            數(shù)據(jù)加載中……

            C++算符優(yōu)先級(jí)表

            http://www.cppreference.com/wiki/operator_precedence

             

            The operators at the top of this list are evaluated first. Operators within a group have the same precedence. All operators have left-to-right associativity unless otherwise noted.

             

            Precedence

            Operator

            Description

            Example

            Overloadable

            Associativity

            1

            ::

            Scope resolution operator

            Class::age = 2;

            no

            left to right

            2

            ()
            ()
            []
            ->
            .
            ++
            --
            dynamic_cast
            static_cast
            reinterpret_cast
            const_cast
            typeid

            Function call
            Member initalization
            Array access
            Member access from a pointer
            Member access from an object
            Post-increment
            Post-decrement
            Runtime-checked type conversion
            Unchecked type conversion
            Reinterpreting type conversion
            Cast away/Add constness
            Get type information

            isdigit('1')
            c_tor(int x, int y) : _x(x), _y(y * 10) {}
            array[4] = 2;
            ptr->age = 34;
            obj.age = 34;
            for (int i = 0; i < 10; i++) cout << i;
            for (int i = 10; i > 0; i--) cout << i;
            Y& y = dynamic_cast<Y&>(x);
            Y& y = static_cast<Y&>(x);
            int const* p = reinterpret_cast<int const*>(0x1234);
            int* q = const_cast<int*>(p);
            std::type_info const& t = typeid(x);

            yes
            yes
            yes
            yes
            no
            yes
            yes
            no
            no
            no
            no
            no

            left to right

            3

            !
            not
            ~
            compl
            ++
            --
            -
            +
            *
            &
            sizeof
            new
            new []
            delete
            delete []
            (type)

            Logical negation
            Alternate spelling for !
            Bitwise complement
            Alternate spelling for ~
            Pre-increment
            Pre-decrement
            Unary minus
            Unary plus
            Dereference
            Address of
            Size (of the type) of the operand in bytes
            Dynamic memory allocation
            Dynamic memory allocation of array
            Deallocating the memory
            Deallocating the memory of array
            Cast to a given type

            if (!done) …

            flags = ~flags;

            for (i = 0; i < 10; ++i) cout << i;
            for (i = 10; i > 0; --i) cout << i;
            int i = -1;
            int i = +1;
            int data = *intPtr;
            int *intPtr = &data;
            size_t s = sizeof(int);
            long* pVar = new long;
            long* array = new long[20];
            delete pVar;
            delete [] array;
            int i = (int)floatNum;

            yes

            yes

            yes
            yes
            yes
            yes
            yes
            yes
            no
            yes
            yes
            yes
            yes
            yes

            right to left

            4

            ->*
            .*

            Member pointer selector
            Member object selector

            ptr->*var = 24;
            obj.*var = 24;

            yes
            no

            left to right

            5

            *
            /
            %

            Multiplication
            Division
            Modulus

            int i = 2 * 4;
            float f = 10.0 / 3.0;
            int rem = 4 % 3;

            yes
            yes
            yes

            left to right

            6

            +
            -

            Addition
            Subtraction

            int i = 2 + 3;
            int i = 5 - 1;

            yes
            yes

            left to right

            7

            <<
            >>

            Bitwise shift left
            Bitwise shift right

            int flags = 33 << 1;
            int flags = 33 >> 1;

            yes
            yes

            left to right

            8

            <
            <=
            >
            >=

            Comparison less-than
            Comparison less-than-or-equal-to
            Comparison greater-than
            Comparison greater-than-or-equal-to

            if (i < 42) …
            if (i <= 42) ...
            if (i > 42) …
            if (i >= 42) ...

            yes
            yes
            yes
            yes

            left to right

            9

            ==
            eq
            !=
            not_eq

            Comparison equal-to
            Alternate spelling for ==
            Comparison not-equal-to
            Alternate spelling for !=

            if (i == 42) ...

            if (i != 42) …

            yes
            -
            yes

            left to right

            10

            &
            bitand

            Bitwise AND
            Alternate spelling for &

            flags = flags & 42;

            yes

            left to right

            11

            ^
            xor

            Bitwise exclusive OR (XOR)
            Alternate spelling for ^

            flags = flags ^ 42;

            yes

            left to right

            12

            |
            bitor

            Bitwise inclusive (normal) OR
            Alternate spelling for |

            flags = flags | 42;

            yes

            left to right

            13

            &&
            and

            Logical AND
            Alternate spelling for &&

            if (conditionA && conditionB) …

            yes

            left to right

            14

            ||
            or

            Logical OR
            Alternate spelling for ||

            if (conditionA || conditionB) ...

            yes

            left to right

            15

            ? :

            Ternary conditional (if-then-else)

            int i = a > b ? a : b;

            no

            right to left

            16

            =
            +=
            -=
            *=
            /=
            %=
            &=
            and_eq
            ^=
            xor_eq
            |=
            or_eq
            <<=
            >>=

            Assignment operator
            Increment and assign
            Decrement and assign
            Multiply and assign
            Divide and assign
            Modulo and assign
            Bitwise AND and assign
            Alternate spelling for &=
            Bitwise exclusive or (XOR) and assign
            Alternate spelling for ^=
            Bitwise normal OR and assign
            Alternate spelling for |=
            Bitwise shift left and assign
            Bitwise shift right and assign

            int a = b;
            a += 3;
            b -= 4;
            a *= 5;
            a /= 2;
            a %= 3;
            flags &= new_flags;

            flags ^= new_flags;

            flags |= new_flags;

            flags <<= 2;
            flags >>= 2;

            yes
            yes
            yes
            yes
            yes
            yes
            yes

            yes

            yes

            yes
            yes

            right to left

            17

            throw

            throw exception

            throw EClass(“Message”);

            no

             

            18

            ,

            Sequential evaluation operator

            for (i = 0, j = 0; i < 10; i++, j++) …

            yes

            left to right

            窗體頂端

            窗體底端

            Order of Evaluation and of Side Effects

            One important aspect of C++ that is related to operator precedence, is the order of evaluation and the order of side effects in expressions. In most circumstances, the order in which things happen is not specified. For example in f() + g() whether f() or g() is called first is not specified. If at least one of the functions has side effects the results may differ across compilers, different versions of the same compiler or even between multiple runs of the same compiler.

            Further, the effect of certain expressions is undefined. For example, consider the following code:

                float x = 1;

                x = x / ++x;

            The value of x and the rest of the behaviour of the program after evaluating this expression is undefined. The program is semantically ill-formed: x is modified twice between two consecutive sequence points.

            Expressions like the one above must be avoided. When in doubt, break a large expression into multiple statements to ensure that the order of evaluation is correct.

            窗體頂端

            窗體底端

            Overloading of Operators

            Overloading of operators can be very useful and very dangerous. On one hand overloading operators for a class you have created can help with logistics and readability of code. On the other hand you can overload an operator in such a way that it can either obfuscate or just downright break your program. Use carefully. In particular never overload &&, || or ,. In the overloaded context they lose the guarantee that the left operand is evaluated before the second and that there is a sequence point inbetween.

            There are two ways to over load an operator: global function or class member.

            Example of overloading with a global function:

                 ostream& operator <<(ostream& os, const myClass& rhs);

            But to be able to reach any private data within a user defined class you have to declare the global function as a friend within the definition of the class.

            Example:

                 class myClass {

             

                   // Gives the operator << function access to 'myData'

                   // (this declaration should not go in public, private or protected)

                   friend ostream& operator <<(ostream& lhs, const myClass& rhs);

             

                   private:

                     int myData;

                 }

            Overloading with a class member can be done as follows:

                 class myClass {

             

                   public:

                     // The left hand side of this operator becomes '*this'.

                     int operator +(const myClass& rhs);

             

                   private:

                     int myData;

                 }

             

            posted on 2010-05-06 21:58 肥仔 閱讀(1066) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C++ 基礎(chǔ)LEX & YACC

            久久免费99精品国产自在现线| 无码乱码观看精品久久| 久久久噜噜噜久久中文字幕色伊伊 | 中文字幕无码精品亚洲资源网久久| 无码国内精品久久人妻| 97精品伊人久久久大香线蕉| 亚洲综合久久夜AV | 国产香蕉97碰碰久久人人| 中文字幕热久久久久久久| 久久精品成人免费看| 国产成年无码久久久免费| 国产精品久久国产精品99盘| 久久久久波多野结衣高潮| 久久精品国内一区二区三区| 一级a性色生活片久久无| 久久久久免费精品国产| 波多野结衣中文字幕久久| 久久婷婷五月综合色奶水99啪| 欧美午夜A∨大片久久| 久久精品国产第一区二区三区| 亚洲国产另类久久久精品| 久久99精品国产99久久6| 国产麻豆精品久久一二三| 久久99久久99精品免视看动漫| 国产亚洲精午夜久久久久久| 97久久综合精品久久久综合| 中文字幕久久久久人妻| 久久久精品国产| 久久免费看黄a级毛片| 久久天天日天天操综合伊人av | 精品久久久久久无码专区不卡| 麻豆久久久9性大片| 亚洲国产成人久久综合碰| 国产福利电影一区二区三区久久老子无码午夜伦不 | 无码人妻久久一区二区三区免费丨| 一本久久a久久精品综合夜夜| 99久久精品国产高清一区二区| 天天躁日日躁狠狠久久| 久久99久久99精品免视看动漫| 久久久久久综合网天天| 亚洲中文字幕久久精品无码APP |