November 2001
Beginner
1128 pages
29h 12m
English
Meanwhile, there's more to be done with the Stock class. There are certain standard functions, called constructors and destructors, that you should normally provide for a class. Let's see why they are needed and how to write them.
One of C++'s aims is to make using class objects similar to using standard types. However, you can't yet initialize a Stock object the way you can an ordinary int or struct:
int year = 2001; // okay
struct thing
{
char * pn;
int m;
};
thing amabob = {"wodget", -23}; //okay
Stock hot = {"Sukie's Autos, Inc.", 200, 50.25}; // NO!
The reason you can't initialize a Stock object this way is because the data parts have private access status, which means a program cannot access the data ...