C programming

C programming - C PROGRAMMING Chapter 10 Advanced Functions...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ PROGRAMMING Chapter 10 Advanced Functions Overloaded Member Functions Listing 10.1. Overloading member functions . Using Default Values , Listing 10.2. Using default values . Choosing Between Default Values and Overloaded Functions The Default Constructor , Overloading Constructors Listing 10.3. Overloading the constructor . , Initializing Objects Listing 10.4. A code snippet showing initialization of member variables . The Copy Constructor Figure 10.1. , Figure 10.2. Listing 10.5. Copy constructors . , Figure 10.3. Operator Overloading Listing 10.6. The Counter class . Writing an Increment Function Listing 10.7. Adding an increment operator . Overloading the Prefix Operator Listing 10.8. Overloading operator ++. Returning Types in Overloaded Operator Functions Listing 10.9. Returning a temporary object . Returning Nameless Temporaries Listing 10.10. Returning a nameless temporary object . Using the this Pointer Listing 10.11. Returning the this pointer . Overloading the Postfix Operator Difference Between Prefix and Postfix Listing 10.12. Prefix and postfix operators . Operator Overloading Unary Operators The Addition Operator Listing 10.13. The Add() function . Overloading operator+ Listing 10.14. operator +. Operator Overloading: Binary Operators Issues in Operator Overloading , Limitations on Operator Overloading , What to Overload , The Assignment Operator Listing 10.15. An assignment operator . Conversion Operators Listing 10.16. Attempting to assign a Counter to a USHORT . Listing 10.17. Converting USHORT to Counter . Conversion Operators Listing 10.18. Converting from Counter to unsigned short(). Summary , Q&A , Quiz , Exercises
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Chapter 10 Advanced Functions On Chapter 5, "Functions," you learned the fundamentals of working with functions. Now that you know how pointers and references work, there is more you can do with functions. ToChapter you learn How to overload member functions. How to overload operators. How to write functions to support classes with dynamically allocated variables. Overloaded Member Functions On Chapter 5, you learned how to implement function polymorphism, or function overloading, by writing two or more functions with the same name but with different parameters. Class member functions can be overloaded as well, in much the same way. The Rectangle class, demonstrated in Listing 10.1, has two DrawShape() functions. One, which takes no parameters, draws the Rectangle based on the class's current values. The other takes two values, width and length , and draws the rectangle based on those values, ignoring the current class values. Listing 10.1. Overloading member functions. 1: //Listing 10.1 Overloading class member functions 2: #include <iostream.h> 3: 4: typedef unsigned short int USHORT; 5: enum BOOL { FALSE, TRUE}; 6: 7: // Rectangle class declaration 8: class Rectangle 9: { 10: public: 11: // constructors 12: Rectangle(USHORT width, USHORT height); 13: ~Rectangle(){} 14: 15: // overloaded class function DrawShape 16: void DrawShape() const; 17:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/13/2012 for the course CS 131 taught by Professor Clayton during the Spring '08 term at Bethune Cookman.

Page1 / 37

C programming - C PROGRAMMING Chapter 10 Advanced Functions...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online