forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex15.8.9.10.cpp
51 lines (45 loc) · 1.67 KB
/
ex15.8.9.10.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/***************************************************************************
* @file main.cpp
* @author Alan.W
* @date 21 Jan 2014
* @remark This code is for the exercises from C++ Primer 5th Edition
* @note
***************************************************************************/
//
// Exercise 15.8:
// Define static type and dynamic type.
// The static type of an expression is always known at compile time.
// The dynamic type is the type of the object in memory that the variable or
// expression represents. The dynamic type may not be known until run time.
//
// Exercise 15.9:
// When is it possible for an expression’s static type to differ from its
// dynamic type? Give three examples in which the static and dynamic type differ.
// The static type of a pointer or reference to a base class may differ from
// its dynamic type. Anying like this can be an example
//
// Exercise 15.10:
// Recalling the discussion from §8.1 (p. 311), explain how the program on
// page 317 that passed an ifstream to the Sales_data read function works.
// the function takes a std::istream from which std::ifstream is derived.
// Hence the ifstream object "is a" istream , which is why it works.
//
#include <iostream>
#include <string>
#include <istream>
#include <fstream>
#include "quote.h"
#include "bulk_quote.h"
#include "limit_quote.h"
double print_total (std::ostream& os, const Quote& item, size_t n);
int main()
{
return 0;
}
double print_total(std::ostream &os, const Quote &item, size_t n)
{
double ret = item.net_price(n);
os << "ISBN:" << item.isbn()
<< "# sold: " << n << " total due: " << ret << std::endl;
return ret;
}