October 1997
Intermediate to advanced
800 pages
20h 48m
English
| 1: | Study the following class definition.
class X {
private:
double m;
static double n;
X member1; // illegal
static X member2; // legal
public:
X(double d = m); // illegal
X(int, double d = n); // legal
void f(double v = n); // legal
};
Note that static data members may appear as default arguments to member functions and constructors of the same class. Also, static data members may be objects of the class they belong to. Can you explain why these statements are legal with static data members but illegal for nonstatic members? |
| 2: | Compile the following program and compare its output on your machine to what is shown here.
// count.C - Object creation and deletion #include <iostream.h> class X { private: static int count; public: ... |