Welcome to the GDNet C++ Workshop – Ch. 8For a complete introduction to this workshop, please look here.
This workshop is designed to aid people in their journey to learn beginning C++. This workshop is targeted at highly motivated individuals who are interested in learning C++ or who have attempted to learn C++ in the past, but found that without sufficient support and mentoring they were unable to connect all the pieces of this highly complex but powerful programming language. This is a 'guided' self-teaching C++ workshop. Each student is responsible for taking the time to read the material and learn the information. The community and tutors that arise out of this workshop are here for making the learning process run more smoothly, but are not obligated to baby-sit a person's progress. Because everyone will be working from the same textbook (Teach Yourself C++ in 21 days 5th Ed.
), students may find it easier to get answers to the specific questions they might have. There is no minimum age requirement, and there is no previous programming experience required.
Additionally, this workshop does not attempt to defend C++ as a language, nor does it attempt to demonstrate that C++ is either more or less useful then other programming languages for any particular purpose. People who intend to start a discussion about the differences between C++ and ANY other languages (except as are relevant to a particular discussion), are encouraged to do so elsewhere. This workshop is for educational, not philosophical discussions.
Quizzes & Exercises
Each week will have quizzes and exercises posted in the weekly threads. Please try and answer them by yourself. As well, please DO NOT
post the answers to Quizzes and Exercises within this thread. Once it becomes acceptable to post the answers to quizzes and exercises, an additional thread will be created each week specifically for the purpose of posting quiz answers.
If you try with reasonable effort but are unable to answer the questions or complete the exercises, feel free to post a clarification question here on the thread. Tutors, myself, or others will do the best we can to point you in the right direction for finding the answer.
Chapter 8 – Understanding PointersIntroduction
For many, chapter 8 will be the most difficult in the book, and for a few, pointers will continue to be the most challenging aspect of the C++ programming language. The primary reason for this, I suspect, is that while pointers provide direct access to your memory, they are used via a layer of indirection, ie...they are variables which store the address of your data. So in order to access the contents of the data at that place in memory, you must first dereference the pointer. This seems tragically difficult to grasp at first. The power of pointers, however, is extraordinary. It brings with it quick access to heap memory, faster passing of data, and the ability to dynamically allocate memory to store data on the heap. You are now able to propogate the changes made to function arguments by passing the address of the data and you can dynamically reinterpret the contents of your memory. All good things. But as was once said, "great power comes with great responsibility" - in this case, memory cleanup.
I suspect there will be many questions this week. So have your thinking caps on.
Please remember to use OPINION and WARNING tags whenever applicable. As well, feel free to post your own insights, and review questions or exercises beginning Wednesday or Thursday.
Outline of the Reading - Chapter 8
- What is a pointer?
- Why Would You Use Pointers?
- The Stack and The Free Store (Heap)
- Another Look at Memory Leaks
- Creating Object on The Free Store
- Deleting Object From The Free Store
- Accessing Data Members
- Creating Member Data on The Free Store
- The this Pointer
- Stray, Wild, or Dangling Pointers
- Using const Pointers
[Edited by - jwalsh on May 30, 2007 12:59:25 PM]