TAILIEUCHUNG - Thinking in c volume 1 - 2nd edition - phần 5

phần đầu tập tin (có lẽ một trong đó là của ngày), trang trí tên cung cấp một mạng lưới an toàn thường được gọi là liên kết an toàn loại. Hãy xem xét kịch bản sau đây. Trong một tập tin là định nghĩa cho một chức năng | header file perhaps one that is out of date the name decoration provides a safety net that is often referred to as type-safe linkage. Consider the following scenario. In one file is the definition for a function C07 o Function definition void f int In the second file the function is misdeclared and then called C07 L Def Function misdeclaration void f char int main f 1 Causes a linker error Even though you can see that the function is actually f int the compiler doesn t know this because it was told - through an explicit declaration - that the function is f char Thus the compilation is successful. In C the linker would also be successful but not in C . Because the compiler decorates the names the definition becomes something like f_int whereas the use of the function is f_char When the linker tries to resolve the reference to f_char it can only find f_int and it gives you an error message. This is type-safe linkage. Although the problem doesn t occur all that often when it does it can be incredibly difficult to find especially in a large project. This is one of the cases where you can easily find a difficult error in a C program simply by running it through the C compiler. 332 Thinking in C www. BruceEckel .com Overloading example We can now modify earlier examples to use function overloading. As stated before an immediately useful place for overloading is in constructors. You can see this in the following version of the Stash class C07 Function overloading ifndef STASH3_H define STASH3_H class Stash int size Size of each space int quantity Number of storage spaces int next Next empty space Dynamically allocated array of bytes unsigned char storage void inflate int increase public Stash int size Zero quantity Stash int size int initQuantity Stash int add void element void fetch int index int count . . endif STASH3_H The first Stash constructor is the same as before but the second one has a Quantityargument to indicate the initial number of .

TỪ KHÓA LIÊN QUAN
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.