Wrox Press C++ Tutorial
Summary
In this chapter, we've laid the foundations for object-oriented programming, and in the next chapter, we'll complete the knowledge of classes that you will need to understand how to apply classes to your own applications.
The key points to keep in mind from this chapter are:
-
Objects are destroyed using functions called destructors. It is essential to define a destructor to destroy objects which contain members that are allocated by
new, as the default constructor will not do this.
-
The compiler will supply a default copy constructor for your class if you do not define one. The default copy constructor will not deal correctly with objects of classes that have data members allocated on the free store.
-
When you define your own copy constructor, you must use a reference parameter.
-
If you do not define an assignment operator for your class, the compiler will supply a default version. As with the copy constructor, the default assignment operator will not work correctly with classes that have data members allocated on the free store.
-
It is essential that you provide a destructor, a copy constructor and an assignment operator for classes that have members allocated by
new.
-
A union is a mechanism that allows two or more variables to occupy the same location in memory.
-
A struct is like a class, except that the default access specifier is
public.
-
Most basic operators can be overloaded to provide actions specific to objects of a class. You should only implement operator functions for your classes that are consistent with the normal interpretation of the basic operators.
-
A class template is a pattern that you can use to create classes with the same structure, but which support different data types.
-
You can define a class template that has multiple parameters, including parameters that can assume constant values, rather than types.
-
You should put definitions for your program in
.h files, and executable code - function definitions - in .cpp files. You then can incorporate .h files into your .cpp files by using #include directives.
-
By using the Visual C++ integrated development environment and the Wizard Bar, you can automate a lot of the work in accessing and modifying your program code.
© 1998 Wrox Press