Lecture Object oriented programming - Lecture no 05

In the previous chapter, we looked at UML class diagrams. This chapter continues the study of the static view of software by looking at typical patterns found in class diagrams. These patterns recur in many designs; by learning and using them you are reusing the collective experience of many software developers. | CSC241: Object Oriented Programming Lecture No 05 Previous Lecture Overloaded function Constructor const (constant) object member function data member object as function argument friend function this pointer Today’s Lecture Reference variable this pointer Cascading function calls Dynamic memory allocation static class member static functions static data member sdaf C++ Reference variable C++ references allow you to create a second name for a memory location that you can use to read or modify the original data stored in that location Syntax int& foo = ; reference to an int When a reference is created, you must tell it which variable it will become an alias for Cont. int x; int& y = x; y = 50; cout> feet; cout > inches; } void showdist(){ cout = ) { -= ; = 1; } += feet + ; return temp; } * , -> and dot operator with structure *p s 7550 10 10 7550 10 10 10 10 Implicitly and Explicitly Use this Pointer Go to program Cascading function calls using this pointer In cascaded member-function calls invoked multiple functions in the same statement (Ref. of object t) (Ref. of object t) Example – Time class Cont. Why does the technique of returning *this as a reference work? The dot operator (.) associates from left to right first it evaluates ( 18 ) then returns a reference to .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.