From c91b7ee785bd60360a9b890255693e8d3c5481e4 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Mon, 10 Feb 2025 16:52:07 -0500 Subject: [PATCH] main: got the variable onto the heap ... Signed-off-by: Vincent Batts --- common.h | 3 ++- main.cpp | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/common.h b/common.h index 93fe5f2..e046400 100644 --- a/common.h +++ b/common.h @@ -4,12 +4,13 @@ #include +// https://www.geeksforgeeks.org/cpp-macros/# + #define log_out(hurr) \ std::cout << "[" << __FILE__ << ":" << __LINE__ << "] " << hurr << std::endl; #define log_err(hurr) \ std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] " << hurr << std::endl; - #endif // COMMON_H_INCLUDED_ // vim:set sts=2 sw=2 et: diff --git a/main.cpp b/main.cpp index cc361b9..d2f2694 100644 --- a/main.cpp +++ b/main.cpp @@ -24,19 +24,20 @@ #include "worker.h" Account* do_account() { - Account account(0.0); + Account* account = new Account(0.0); - account.deposit(100.5); // Add some money - account.deposit(50.25); // Add more money - std::cout << "Current Balance: " << account.getBalance() << std::endl; - log_out("HERE"); - return &account; + account->deposit(100.5); // Add some money + account->deposit(50.25); // Add more money + log_out("Current Balance: " << account->getBalance()); + return account; } void scoped_account() { log_out("HERE"); - auto account = do_account(); + Account* account = do_account(); log_out("HERE"); + account->withdraw(100); + log_out("Current Balance: " << account->getBalance()); log_err("dang"); }