Paul S. Cilwa

Intro to C++

These course materials were jointly created by myself and James Kearney, owner of Messaging Systems Group, one of the corporations through which I taught prior to 9/11/01.

Before you can make any use of Visual C++ and the Microsoft Foundation Classes, you have to know C++...and I mean, well. MFC builds on every feature of the C++ language, including Run-Time Type Identification, templates, inheritance, polymorphism, and, of course, object-oriented programming.

Course Duration

This course, typically presented in two days, brings the experienced C programmer up to speed in object-oriented C++; it also serves as a refresher for the C++ programmer who can't quite remember how to use templates or some of the features of the Standard Template Library.

Working Environment

Although the course is taught using Visual C++ as the development environment, it is taught Windows-free: No knowledge of Windows is required, or will be learned, with this course. (It does, however, make the perfect lead-in to Intro to MFC.)

Prerequisites

  • At least three months’ experience programming in the C Language, or 
  • Having recently taken a course in the C Language

Outline

Movin’ On Up to C++

In this chapter, we explore the features added to C++, over the ones normally part of the C language, other than objects; including

  • The distinction between declarations and definitions
  • The C++ manner of creating global variables
  • Three things you can do in C, that you can't do in C++
  • Function signatures and overloaded functions
  • The mechanism of name mangling (name decoration)
  • How to prevent recursive #include statements
  • C++-style comments
  • The const keyword and its implications
  • The four new casting operators static_cast, const_cast, reinterpret_cast, and dynamic_cast
  • New data type bool
  • Namespaces
  • Unrestricted variable definition
  • New C++ initialization style
  • Default parameters
  • Passing arguments by reference
  • The new and delete operators
  • Console interaction with the cin and cout Standard Template Library objects

Properties and Methods of the C++ Class

This chapter introduces classes, the core of C++ object-oriented programming, by designing and building a text class.

  • How to identify an Object
  • The difference between and object and a class
  • Interfaces and Implementations
  • Properties, Methods and Events
  • C++ Object-Oriented Terminology
  • Designing and implementing a text string class
  • Declaring classes
  • The public and private  keywords
  • Constructors and what they do
  • Copy constructors
  • Difference between shallow and deep copy
  • Overloaded constructors
  • Destructors and what they do
  • Constructor initializer Lists
  • The this keyword
  • const and static members
  • Temporary objects

Overloaded Operators and Streams

This chapter expands the concept of function overloading to include operator functions, and enhances the text class to work with the Standard Template Library stream objects, to demonstrate the point.

  • Operator overloading
  • Difference between class and global operator functions
  • friend functions
  • Enhancing standard stream behaviors

Inheritance

This chapter introduces the concept of Inheritance, demonstrated by deriving a new number class from the text class we designed earlier.

  • The concept of inheritance
  • Deriving a class
  • The protected keyword
  • Sizes of derived class objects
  • What gets inherited
  • What does not get inherited
  • Constructor and destructor implications
  • Exposing hidden inherited members
  • Multiple inheritance
  • virtual inheritance

Containers and Polymorphism

This final chapter introduces the concept of polymorphism, and demonstrates its use with an additional class, currency, derived from number, and container classes from the Standard Template Library.

  • Concept of polymorphism
  • Early binding vs. run-time binding
  • virtual functions
  • Abstract classes
  • Pure virtual functions
  • Run-time type identification
  • Templates
  • Template classes
  • Exception handling