Skip to content

Commit

Permalink
refactor ex15_26
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Jun 11, 2015
1 parent b7545bf commit be8f6fe
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 341 deletions.
6 changes: 6 additions & 0 deletions ch15/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,9 @@ error: use of deleted function 'Bulk_quote::Bulk_quote()'
```
The reason is that a constructor taking 4 parameters has been defined, which prevented the compiler generate synthesized version default constructor. As a result, the default constructor of any class derived from it has been defined as deleted. Thus the default constructor must be defined explicitly so that the derived classes can call it when executing its default constructor.
## Exercise 15.26:
> Define the `Quote` and `Bulk_quote` copy-control members to do the same job as the synthesized versions. Give them and the other constructors print statements that identify which function is running. Write programs using these classes and predict what objects will be created and destroyed. Compare your predictions with the output and continue experimenting until your predictions are reliably correct.
- [Quote](ex15_26_Quote.h)
- [Bulk_quote](ex15_26_Bulk_quote.h)
65 changes: 49 additions & 16 deletions ch15/TEST.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#include "ch15.h"
using namespace ch15;
#include "ex15_03_Quote.h"
#include "ex15_05_Bulk_quote.h"
#include "ex15_07_Limit_quote.h"
#include "ex15_11_Quote.h"
#include "ex15_11_Bulk_quote.h"
#include "ex15_11_Limit_quote.h"
#include "ex15_15_Disc_quote.h"
#include "ex15_15_Bulk_quote.h"
#include "ex15_16_Limit_quote.h"
#include "ex15_20_Base.h"
#include "ex15_21_GeomtricPrimitives.h"
#include "ex15_26_Quote.h"
#include "ex15_26_Bulk_quote.h"

int main()
{
Expand Down Expand Up @@ -40,22 +51,20 @@ int main()

cout << "\n===== ex20 =====" << endl;

EX20::Pub_Derv d1;
EX20::Priv_Derv d2;
EX20::Prot_Derv d3;
//EX20::Pub_Derv d1;
//EX20::Priv_Derv d2;
//EX20::Prot_Derv d3;

EX20::Derived_from_Public dd1;
EX20::Derived_from_Private dd2;
EX20::Derived_from_Protected dd3;
//EX20::Derived_from_Public dd1;
//EX20::Derived_from_Private dd2;
//EX20::Derived_from_Protected dd3;

{
EX20::Base *p = &d1;
// p = &d2; // error: inaccessible
// p = &d3; // error: inaccessible
p = &dd1;
// p = &dd2; // error: inaccessible
// p = &dd3; // error: inaccessible
}
//EX20::Base *p = &d1;
// p = &d2; // error: inaccessible
// p = &d3; // error: inaccessible
//p = &dd1;
// p = &dd2; // error: inaccessible
// p = &dd3; // error: inaccessible

cout << "\n===== ex21 =====" << endl;

Expand All @@ -78,4 +87,28 @@ int main()
cout << cone.shape_name();
cone.resize_by_percentage(2.f);
cout << "'s volume = " << cone.volume() << endl;

cout << "\n===== ex26 =====" << endl;

EX26::Quote quote_26;
EX26::Quote quote_26_p("0-201-78345-X", 23.8);
EX26::Quote quote_26_cp(quote_26_p);
EX26::Quote quote_26_mv(std::move(quote_26_p));

cout << "------ISBN: price------" << endl;
cout << quote_26.isbn() << ": " << quote_26.net_price(3) << endl;
cout << quote_26_cp.isbn() << ": " << quote_26_cp.net_price(3) << endl;
cout << quote_26_mv.isbn() << ": " << quote_26_mv.net_price(3) << endl;
cout << "-----------------------" << endl;

EX26::Bulk_quote bulk_26;
EX26::Bulk_quote bulk_26_p("0-201-78345-X", 23.8, 3, 0.5);
EX26::Bulk_quote bulk_26_cp(bulk_26_p);
EX26::Bulk_quote bulk_26_mv(std::move(bulk_26_p));

cout << "------ISBN: price------" << endl;
cout << bulk_26.isbn() << ": " << bulk_26.net_price(3) << endl;
cout << bulk_26_cp.isbn() << ": " << bulk_26_cp.net_price(3) << endl;
cout << bulk_26_mv.isbn() << ": " << bulk_26_mv.net_price(3) << endl;
cout << "-----------------------" << endl;
}
33 changes: 0 additions & 33 deletions ch15/ch15.h

This file was deleted.

13 changes: 0 additions & 13 deletions ch15/ex15.26/bulk_quote.cpp

This file was deleted.

53 changes: 0 additions & 53 deletions ch15/ex15.26/bulk_quote.h

This file was deleted.

2 changes: 0 additions & 2 deletions ch15/ex15.26/disc_quote.cpp

This file was deleted.

79 changes: 0 additions & 79 deletions ch15/ex15.26/disc_quote.h

This file was deleted.

9 changes: 0 additions & 9 deletions ch15/ex15.26/limit_quote.cpp

This file was deleted.

19 changes: 0 additions & 19 deletions ch15/ex15.26/limit_quote.h

This file was deleted.

36 changes: 0 additions & 36 deletions ch15/ex15.26/main.cpp

This file was deleted.

8 changes: 0 additions & 8 deletions ch15/ex15.26/quote.cpp

This file was deleted.

Loading

0 comments on commit be8f6fe

Please sign in to comment.