Declaring and Defining Constructors
Now you need to build a Stock
constructor. Because a Stock
object has three values to be provided from the outside world, you should give the constructor three arguments. (The fourth value, the total_val
member, is calculated from shares
and share_val
, so you don’t have to provide it to the constructor.) Possibly, you may want to provide just the company
member value and set the other values to zero; you can do this by using default arguments (see Chapter 8, “Adventures in Functions.”). Thus, the prototype would look like this:
// constructor prototype with some default argumentsStock(const string & co, long n = 0, double pr = 0.0);
The first argument is a pointer to the string that is used to initialize the ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.