C++ Workshop - Templates (Ch. 19)

Started by
-1 comments, last by JWalsh 16 years, 11 months ago

Welcome to the GDNet C++ Workshop – Ch. 19

For a complete introduction to this workshop, please look here. Workshop Overview 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 19 – Templates

Introduction Welcome again. This chapter will prove for many to be the most difficult chapter in the book. As a quick overview, this chapter begins by explaining what a template is. In a nutshell, in their original design, templates are simply a way of reducing code bloat while still expanding functionality to support multiple data types. It would be incorrect to describe templates as variable data types, as duplicate code is actually created at compile time to handle each used data type in association with the template, however it is often easiest to think of templates as a system of allowing you to create variable data types. After describing what a template it is dives into the details of building and using a template class. This includes using the class and typename keywords, using the template name, passing instantiated template objects around your codebase, and working with friends involving template classes. The second half of the chapter is the much needed (and it needs much more), introduction to the actual classes within the Standard Template Library. Many people, perhaps rightly so, view the STL as an extension of the language, and opt to use the STL classes as frequently as possible, instead of writing custom code. This is especially true in the case of the string class. As a result, many feel a chapter on the STL should have come sooner in the workshop. I tend to agree, though the complexity of the subject tends to put templates soundly at the back of most modern C++ books. Outline of the Reading - Chapter 19
  1. What are Templates?
  2. Building a Template Definition
  3. Passing Instantiated Template Objects to Functions
  4. Templates and Friends
  5. Using Template Items
  6. The Standard Template Library

Good Luck!

[Edited by - jwalsh on May 30, 2007 5:36:51 PM]
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints

This topic is closed to new replies.

Advertisement