TAILIEUCHUNG - A Complete Guide to Programming in C++ part 60

A Complete Guide to Programming in C++ part 60. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | ABSTRACT AND CONCRETE CLASSES 569 NOTE Concrete or Abstract If a class comprises pure virtual methods you cannot create objects of this class type. Example Coworker worker Black Michael The compiler will issue an error message here as the Coworker class contains the pure virtual method income . This avoids calling a method for worker that still needs to be defined. A class that does not allow you to create any objects is referred to as an abstract class. A class with pure virtual methods is an abstract class. In contrast a class that allows you to create objects is referred to as a concrete class. Deriving Abstract Classes When a class is derived from an abstract class it inherits all the methods the base class contains particularly the pure virtual methods. If all of these pure virtual methods are implemented in the derived class you can then create an object of the derived class type. NOTE A class derived from a class containing pure virtual methods is a concrete class if it contains a definition for each pure virtual function. This means you need to implement the income method in the Laborer class shown opposite. Since the hourly wage and the number of hours worked are both defined for blue-collar workers it is possible to implement that method. Example double Laborer income return wages hr A class derived from a concrete class can again contain pure virtual methods due to additional definitions in the derived class. In other words an abstract class can be derived from a concrete class. An abstract class does not necessarily need to contain pure virtual functions. If the class contains a protected constructor objects of the class type cannot be created. The constructor can only be called then by methods in derived classes. A constructor of this type normally acts as base initializer when an object of a derived class type is created. 570 CHAPTER 26 ABSTRACT CLASSES POINTERS AND REFERENCES TO ABSTRACT CLASSES The derived class Employee Extending the .

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.