TAILIEUCHUNG - Chapter 8 Operator Overloading, Friends, and References

Given previous example: Note: overloaded "+" NOT member function Definition is "more involved" than simple "add", Requires issues of money type addition. Must handle negative/positive values Operator overload definitions generally very simple | Chapter 8 Operator Overloading, Friends, and References Learning Objectives Basic Operator Overloading Unary operators As member functions Friends and Automatic Type Conversion Friend functions, friend classes Constructors for automatic type conversion References and More Overloading > Operators: = , [], ++, -- Operator Overloading Introduction Operators +, -, %, ==, etc. Really just functions! Simply "called" with different syntax: x + 7 "+" is binary operator with x & 7 as operands We "like" this notation as humans Think of it as: +(x, 7) "+" is the function name x, 7 are the arguments Function "+" returns "sum" of it’s arguments Operator Overloading Perspective Built-in operators ., +, -, = , %, ==, /, * Already work for C++ built-in types In standard "binary" notation We can overload them! To work with OUR types! To add "Chair types", or "Money types" As appropriate for our needs In "notation" we’re comfortable with Always overload with similar "actions"! Overloading .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.