TAILIEUCHUNG - Thinking in Cplus plus (P29)

Tham khảo tài liệu 'thinking in cplus plus (p29)', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | public void visit Aluminum al double v al- weight al- value out value of Aluminum v endl alSum v void visit Paper p double v p- weight p- value out value of Paper v endl pSum v void visit Glass g double v g- weight g- value out value of Glass v endl gSum v void visit Cardboard c double v c- weight c- value out value of Cardboard v endl cSum v void total ostream os os Total Aluminum alSum n Total Paper pSum n Total Glass gSum n Total Cardboard cSum endl class Weightvisitor public Visitor double alSum Aluminum double pSum Paper double gSum Glass double cSum Cardboard public void visit Aluminum al alSum al- weight out weight of Aluminum al- weight endl Chapter 16 Design Patterns 501 void visit Paper p pSum p- weight out weight of Paper p- weight endl void visit Glass g gSum g- weight out weight of Glass g- weight endl void visit Cardboard c cSum c- weight out weight of Cardboard c- weight endl void total ostream os os Total weight Aluminum alSum endl os Total weight Paper pSum endl os Total weight Glass gSum endl os Total weight Cardboard cSum endl int main vector Trash bin fillBin still works without changes but different objects are prototyped fillBin bin You could even iterate through a list of visitors Pricevisitor pv Weightvisitor wv vector Trash iterator it while it it - accept pv it - accept wv it out out Chapter 16 Design Patterns 502 purge bin Note that the shape of main has changed again. Now there s only a single Trash bin. The two Visitor objects are accepted into every element in the sequence and they perform their operations. The visitors keep their own internal data to tally the total weights and prices. Finally there s no run-time type identification other than the inevitable cast to Trash when pulling things out of the sequence. One way you can distinguish this solution from the double dispatching solution described previously is to note that in the double dispatching solution only one of the overloaded .

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.