tailieunhanh - Absolute C++ (4th Edition) part 33

Absolute C++ (4th Edition) part 33. KEY BENEFIT: C++ programming concepts and techniques are presented in a straightforward style using understandable language and code. KEY TOPICS: C++ Basics; Flow of Control; Function Basics; Parameters and Overloading; Arrays; Structures and Classes; Constructors; Operator Overloading, Friends, and References; Strings; Pointers and Dynamic Arrays; Separate Compilation and Namespaces; Streams and File I/O; Recursion; Inheritance; Polymorphism and Virtual Functions; Templates; Linked Data Structures; Exception Handling; Standard Template Library; Patterns and UML. MARKET: Useful for both beginning and intermediate C++ programmers. . | 324 Operator Overloading Friends and References When one class is a friend of another class it is typical for the classes to reference forward declaration each other in their class definitions. This requires that you include a forward declaration to the class defined second as illustrated in the outline that follows this paragraph. Note that the forward declaration is just the heading of the class definition followed by a semicolon. If you want the class F to be a friend of the class C the general outline of how you set things up is as follows class F forward declaration class C public friend class F class F Complete examples using friend classes are given in Chapter 17. We will not be using friend classes until then. Self-Test Exercises 6. What is the difference between a friend function for a class and a member function for the class 7. Complete the definition of the friend subtraction operator - in Display . 8. Suppose you wish to overload the operator so that it applies to the type Money defined in Display . What do you need to add to the definition of Money given in Display References and More Overloaded Operators Do not mistake the pointing finger for the moon. Zen Saying This section covers some specialized but important overloading topics including overloading the assignment operator and the and operators. Because References and More Overloaded Operators 325 Rules on Overloading Operators When overloading an operator at least one parameter one operand of the resulting overloaded operator must be of a class type. Most operators can be overloaded as a member of the class a friend of the class or a nonmember nonfriend. The following operators can only be overloaded as nonstatic members of the class - and . You cannot create a new operator. All you can do is overload existing operators such as - and so forth. You cannot change the number of arguments that an operator takes. For example you cannot change from a binary to a unary operator when you .

TỪ KHÓA LIÊN QUAN