nifty():
nifty (char * s);
ostream & operator << (ostream & os, nifty & n);
nifty: nifty()
personality = NULL;
talents = 0:
-
nifty: nifty (char * s)
personality = new char [strlen (s) ]:
personality * S:
talents = 0:
-
// points to string containing golfer's name
// holds number of golf games played
// points to first element of array of golf scores
// #1
// #2
// #3
// #4
/7 #5
// ¥6
// #7
ostream & nifty: operator << (ostream & os. nifty & n)
os << n:
5. 对于下面的类声明:
class Golfer
private:
char * fullname:
int games:
int * scores:
public:
Golfer ():
Golfer (const char * name, int g= 0);
// creates empty dynamic array of q elements if g > 0
Golfer (const Golfer & g);
-Golfer():
a. ド列各条语句将调用哪些类方法?
Golfer nancy:
Golfer lulu ("Little Lulu") :
Golfer roy ("Roy Hobbs", 12) :
Golfer * par = new Golfer:
Golfer next = lulu;
Golfer hazzard = "Weed Thwacker":
*par = nancy:
nancy = "Nancy Putter":
b. 很明显,类需要有另外几种方法才能更有用,但是类需要那些方法才能防止数据被损坏呢?
12.5
编程练习
1. 对于下面的类声明:
class Cow {
char name [20]:
char * hobby:
double weight:
public:
Cow{):
Cow (const char * nm. const char * ho. double wt);