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

Mặc dù bạn có thể thấy rằng chức năng thực sự là f (int), trình biên dịch không biết điều này bởi vì nó đã nói - thông qua một tuyên bố rõ ràng rằng chức năng f (char). Như vậy, biên dịch thành công. Trong C, các mối liên kết cũng sẽ được thành công, nhưng không phải trong C + + | Improved error checking The have been used up to this point without defining them although assert has also been used to help detect programmer errors where it s appropriate . Now it s time to define this header file. Inline functions are convenient here because they allow everything to be placed in a header file which simplifies the process of using the package. You just include the header file and you don t need to worry about linking an implementation file. You should note that exceptions presented in detail in Volume 2 of this book provide a much more effective way of handling many kinds of errors - especially those that you d like to recover from -instead of just halting the program. The conditions that handles however are ones which prevent the continuation of the program such as if the user doesn t provide enough command-line arguments or if a file cannot be opened. Thus it s acceptable that they call the Standard C Library function exit The following header file is placed in the book s root directory so it s easily accessed from all chapters. Test for error conditions in programs Local using namespace std for old compilers ifndef REQUIRE_H define REQUIRE_H include cstdio include cstdlib include fstream include string inline void require bool requirement const std string msg Requirement failed using namespace std if requirement fputs stderr fputs n stderr exit 1 420 Thinking in C www. BruceEckel .com inline void requireArgs int argc int args const std string msg Must use d arguments using namespace std if argc args 1 fprintf stderr args fputs n stderr exit 1 inline void requireMinArgs int argc int minArgs const std string msg Must use at least d arguments using namespace std if argc minArgs 1 fprintf stderr minArgs fputs n stderr exit 1 inline void assure std ifstream in const std string filename using namespace std if in fprintf stderr Could not open file s n exit 1 inline .

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.