tailieunhanh - Lecture Object oriented programming - Lecture no 08

In this chapter you will learn about the following: Design as a series of design decisions; various approaches and types of design, including top-down design starting with the architecture, and bottom-up design starting with utilities; design principles that lead to maintainable software, such as ‘divide and conquer’, striving for high cohesion and low coupling, as well as using good abstractions to hide details, thus simplifying the system;. | CSC241: Object Oriented Programming Lecture No 08 Previous Lecture Abstract data type (ADT) Container classes Proxy classes Operator overloading Today’s Lecture Operator overloading Overloading unary operator ++ - - Argument of overloaded function Post increment Operator overloading For example, statements like (d1, d2); or the similar but equally obscure d3 = (d2); can be changed to the much more readable d3 = d1 + d2; Examples of c++ overloaded operator Addition + and subtraction – operator +, – operators perform differently, depending on their context in integer arithmetic, floating-point arithmetic and pointer arithmetic. Stream insertion (>) operator (cout>) > is used both as the stream extraction operator and as the bitwise right-shift operator > are overloaded in the C++ Standard Library std Syntax of overloaded operator function | CSC241: Object Oriented Programming Lecture No 08 Previous Lecture Abstract data type (ADT) Container classes Proxy classes Operator overloading Today’s Lecture Operator overloading Overloading unary operator ++ - - Argument of overloaded function Post increment Operator overloading For example, statements like (d1, d2); or the similar but equally obscure d3 = (d2); can be changed to the much more readable d3 = d1 + d2; Examples of c++ overloaded operator Addition + and subtraction – operator +, – operators perform differently, depending on their context in integer arithmetic, floating-point arithmetic and pointer arithmetic. Stream insertion (>) operator (cout>) > is used both as the stream extraction operator and as the bitwise right-shift operator > are overloaded in the C++ Standard Library std Syntax of overloaded operator function An operator is overloaded by writing a non-static member function definition Function name becomes the keyword operator followed by the symbol for the operator being overloaded . operator + () { . } Function name operator+ would be used to overload the addition operator (+) Assignment operator (=) may be used with every class to perform member wise assignment of the data members d1 = d2; Precedence, Associativity and No. of Operands Precedence means which operator to solve first (+, -, *, /, = ) The precedence of an operator cannot be changed by overloading The associativity of an operator cannot be changed by overloading Overloaded unary operators (++, --) remain unary operators overloaded binary operators remain binary operators Creating New Operators It is not possible to create new operators only existing operators can be overloaded . ** can be used for exponential in some programming languages ** is not in the list od existing operator so it cannot be overloaded Attempting

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.