Review of C++ Programming: Sheng-Fang Huang
Review of C++ Programming: Sheng-Fang Huang
Part II
Sheng-Fang Huang
friend
To declare a function as a friend of a class:
Provide the function prototype in the class
definition preceded by keyword friend.
friend Classes
Friendship is granted, not taken
For class B to be a friend of class A, class A must
explicitly declare that class B is its friend
Heap
Region of memory assigned to each program for
storing objects created at execution time
Fundamentals of Operator
Overloading
Types for operator overloading
Built in (int, char) or user-defined (classes)
Can use existing operators with user-defined types
Cannot create new operators
Overloading operators
Create a function for the class
Operator overloading contributes to C++s
extensibilityone of the languages most
appealing attributes
Example program
Class PhoneNumber
Holds a telephone number
};
!s becomes s.operator!()
};
y += z becomes y.operator+=( z )
integers1[ 5 ] calls
integers1.operator[]( 5 )