tailieunhanh - Teach Yourself Visual C++ 6 in 21 Days phần 6

Chúng ta hãy xem xét làm thế nào điều này có thể làm việc với một nhiệt. Giả sử bạn đã có một nhiệt cơ bản mà bạn có thể sử dụng trong chỉ là về bất kỳ thiết lập. Bạn có thể thiết lập nhiệt độ cho nó để duy trì, và nó sẽ bật sưởi ấm hoặc điều hòa không khí cần thiết để duy trì nhiệt độ. | Creating Your Own Classes and Modules 381 I Let s look at how this could work with a thermostat. Suppose you had a basic thermostat that you could use in just about any setting. You could set the temperature for it to maintain and it would turn on the heating or the air-conditioning as needed to maintain that temperature. Now let s say you needed to create a thermostat for use in a freezer. You could start from scratch and build a customized thermostat or you could take your existing thermostat and specify how the freezer version differs from the original. These differences might include that it s limited to turning on the air conditioning and could never turn on the heater. You would probably also put a strict limit on the range of temperatures to which the thermostat could be set such as around and below 32 Fahrenheit or 0 Celsius. Likewise if you needed a thermostat for an office building you would probably want to limit the temperature range to what is normally comfortable for people and not allow the temperature to be set to an extremely cold or hot setting. With inheritance in creating your own classes this method just described represents the same principle that you want to apply. If possible you should start with an existing C class that has the basic functionality that you need and then program how your class is different from the base class that you inherited from. You have the ability to add new data elements extend existing functionality or override existing functionality as you see fit. 16 Visual C Class Types In most application projects when you are creating a new class you have a few options on the type of class that you are creating. These options are Generic class MFC class Form class Which of these types of classes you choose to create depends on your needs and what your class will be doing. It also depends on whether your class needs to descend from any of the MFC classes. Generic Class You use a generic class for creating a class that is .