Answers 863
D
Exercises
- The C++ standard iostreamheader file declares coutand endlin namespace std.
They cannot be used outside of the standard namespace stdwithout a namespace
qualifier. - You can add the following line between lines 0 and 1.
using namespace std;
You can add the following two lines between 0 and 1:
using std::cout;
using std::endl;
You can change line 3 to the following:
std::cout << “Hello world!” << std::endl; - The following is one possible answer:
Namespace MyStuff
{
class MyClass
{
//MyClass stuff
}
}
Day 19
Quiz
- Templates are built in to the C++ language and are type-safe. Macros are imple-
mented by the preprocessor and are not type-safe. - The parameter to the template creates an instance of the template for each type. If
you create six template instances, six different classes or functions are created. The
parameters to the function change the behavior or data of the function, but only
one function is created. - The general template friend function creates one function for every type of the
parameterized class; the type-specific function creates a type-specific instance for
each instance of the parameterized class. - Yes, create a specialized function for the particular instance. In addition to creating
Array::SomeFunction(), also create Array ::SomeFunction()to change
the behavior for integer arrays. - One for each instance type of the class.
32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 863