Thinking in C++ 2nd edition Volume 2 Standard Libraries & Advanced Topics revision 1 phần 7

sau đây hy vọng các đối số dòng lệnh được trong flag1 hình thức = value1 không có khoảng trống xung quanh '=' (vì vậy nó sẽ được đối xử như một đối số duy nhất). Lớp ProgVal chỉ đơn giản là thừa kế từ bản đồ | int main ofstream data assure data Conglomerate C This is Conglomerate C cout C before storage endl data Closes file ifstream data assure data Conglomerate C data cout after storage endl The pure virtual functions in Persistent must be redefined in the derived classes to perform the proper reading and writing. If you already knew that Data would be persistent you could inherit directly from Persistent and redefine the functions there thus eliminating the need for multiple inheritance. This example is based on the idea that you don t own the code for Data that it was created elsewhere and may be part of another class hierarchy so you don t have control over its inheritance. However for this scheme to work correctly you must have access to the underlying implementation so it can be stored thus the use of protected. The classes WDatal and WData2 use familiar iostream inserters and extractors to store and retrieve the protected data in Data to and from the iostream object. In write you can see that spaces are added after each floating point number is written these are necessary to allow parsing of the data on input. The class Conglomerate not only inherits from Data it also has member objects of type WDatal and WData2 as well as a pointer to a character string. In addition all the classes that inherit from Persistent also contain a VPTR so this example shows the kind of problem you ll actually encounter when using persistence. When you create write and read function pairs the read must exactly mirror what happens during the write so read pulls the bits off the disk the same way they were placed there by write . Here the first problem that s tackled is the char which points to a string of any length. The size of the string is calculated and stored on disk as an int followed Chapter 15 Multiple Inheritance 361 by a space to enable parsing to allow the read .

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
272    24    1    02-12-2024
Đã 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.