MCPcopy Create free account
hub / github.com/Apress/design-patterns-in-modern-cpp / BankAccount

Class BankAccount

Structural/NullObject/nullobject.cpp:34–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32};
33
34struct BankAccount
35{
36 shared_ptr<OptionalLogger> log;
37 string name;
38 int balance = 0;
39
40 static shared_ptr<Logger> no_logging;
41
42 BankAccount(const string& name, int balance, const shared_ptr<Logger>& logger = no_logging)
43 : log{make_shared<OptionalLogger>(logger)},
44 name{name},
45 balance{balance}
46 {
47 }
48
49 void deposit(int amount)
50 {
51 balance += amount;
52 log->info("Deposited $" /*+ lexical_cast<string>(amount)
53 + " to " + name + ", balance is now $" + lexical_cast<string>(balance)*/);
54 }
55
56 void withdraw(int amount)
57 {
58 /*if (balance >= amount)
59 {
60 balance -= amount;
61 log->info("Withdrew $" + lexical_cast<string>(amount)
62 + " from " + name + ", $" + lexical_cast<string>(balance) + " left");
63 }
64 else
65 {
66 log->warn("Tried to withdraw $" + lexical_cast<string>(amount) +
67 " from " + name + " but couldn't due to low balance");
68 }*/
69 }
70};
71
72shared_ptr<Logger> BankAccount::no_logging{};
73

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected