Bits and Pieces
- Final: 5/6 8:00 - 10:00
- Look at diamond.cpp quickly.
- Templated classes.
- I built a History Class Template.
- There are many optional things that you can do.
- But you will need to re-read these when you get there.
- The Handle class
- This is an outdated topic.
- This has been replaced by smart pointers.
- This is discussed in Stroustrup, C++ Programming Language, 3rd.
- The idea is to
- Store a pointer to an object.
- And a reference count.
- When the class is constructed set the reference count to 1
- As it is copied increment the reference count.
- As it is deleted, decrease the reference count.
- When the reference count is 0, free the pointer.
- Details:
- The class actually keeps a pointer to an int.
- This pointer is shared across all instances of the class.
- The code is implemented here
- Friends
- We briefly encountered friend functions before.
- Declaring a function a "friend" of a class provides access to all members.
- Gregorie warns us to be careful, this breaks the principles of encapsulation.
- Meyers says don't do it.
- I built an Example