main: trying out assert and validations
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
01101c84a0
commit
98ec9e2a9c
1 changed files with 11 additions and 0 deletions
11
main.cpp
11
main.cpp
|
@ -19,6 +19,7 @@
|
|||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include "./common.h"
|
||||
#include "./account.h"
|
||||
|
@ -26,6 +27,11 @@
|
|||
|
||||
Account* do_account() {
|
||||
Account* account = new Account(0.0);
|
||||
assert(account);
|
||||
if (nullptr == account) {
|
||||
log_err("failed to allocate account");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
account->deposit(100.5); // Add some money
|
||||
account->deposit(50.25); // Add more money
|
||||
|
@ -36,10 +42,15 @@ Account* do_account() {
|
|||
void scoped_account() {
|
||||
log_out("HERE");
|
||||
auto account = do_account();
|
||||
if (nullptr == account) {
|
||||
log_err("failed to allocate account");
|
||||
return;
|
||||
}
|
||||
log_out("HERE");
|
||||
account->withdraw(100);
|
||||
log_out("Current Balance: " << account->getBalance());
|
||||
log_err("dang");
|
||||
delete account;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue