Все работало, пока я не решил попытаться упростить зависимости, потому что меня раздражало передавать все классы через их ссылки. Вот структура, которую я создал для хранения ссылок:
Код: Выделить всё
#pragma once
#include "pch.h"
#include "Accounts/UserBusiness/BusinessManager.h"
#include "Accounts/UserBusiness/Clients/ClientManager.h"
#include "Stock/StockManager.h"
//#include "InvoiceSystem/InvoiceData/InvoiceManager.h"
struct AppContext {
AccountManager& accountMgr;
BusinessManager& businessMgr;
MongoDBDataManager& dbMgr;
//ClientManager& cliManager;
//StockManager& stkMgr;
//InvoiceManager& invoiceMgr;
};
Код: Выделить всё
int main() {
/*Main Executable*/
/*Invoice Menu*/
AccountManager accountManager;
BusinessManager businessManager;
MongoDBDataManager dbManager;
auto user = std::make_shared("test@email.com", "password123");
user->setMongoUserID("USR00000001");
accountManager.setTestUser(user);
businessManager.setBusinessGlobally("BUS00000001");
// Create context
AppContext ctx{ accountManager, businessManager, dbManager, /*cliManager, stkManager*/ };
ClientManager cliManager(ctx);
StockManager stkManager(ctx);
BusinessMenu businessMenu(ctx);
InvoiceMenu invoiceMenu(ctx, stkManager, cliManager);
invoiceMenu.setTestUser(user);
invoiceMenu.displayInvoiceMenu();
return 0;
}
Код: Выделить всё
'appCtx': undeclared identifier
'appCtx': undeclared identifier
'appCtx': undeclared identifier
'appCtx': undeclared identifier
'appCtx': undeclared identifier
'ClientManager': illegal member initialization: 'appCtx' is not a base or member
'ClientManager::dbManager': a reference type cannot be value-initialized
'StockManager': illegal member initialization: 'appCtx' is not a base or member
'StockManager::businessManager': a reference type cannot be value-initialized
'StockManager::dbManager': a reference type cannot be value-initialized
syntax error: identifier 'AppContext'
syntax error: identifier 'AppContext'
syntax error: missing ';' before '&'
syntax error: missing ';' before '&'
The member function can be made const.
unexpected token(s) preceding ';'
unexpected token(s) preceding ';'
Код: Выделить всё
class InvoiceMenu {
public:
InvoiceMenu(AppContext& appCtx, StockManager& stkMgr, ClientManager& cliManager) : appCtx(appCtx), invoiceDetails(appCtx),
cliManager(cliManager), stkMgr(stkMgr){}
void setTestUser(std::shared_ptr user) {
testUser = user;
}
void displayInvoiceMenu();
private:
AppContext& appCtx;
StockManager& stkMgr;
void createInvoice();
std::shared_ptr currentUser;
std::map businessMap;
InvoicePdfGenerator generator;
std::shared_ptr testUser;
InvoiceDetails invoiceDetails;
ClientManager& cliManager;
};
Код: Выделить всё
class StockManager {
public:
StockManager(AppContext& appCtx) : appCtx(appCtx) ,
dbManager(appCtx.dbMgr), businessManager(appCtx.businessMgr) {}
void displayAllStock();
std::optional stockMap();
std::optional createSearchMap();
std::unordered_map stkMap;
static void setStockItem(const std::string& stkID);
static std::shared_ptr getCurrentStockItem();
private:
AppContext& appCtx;
BusinessManager& businessManager;
MongoDBDataManager& dbManager;
static std::shared_ptr currentItem;
};
Код: Выделить всё
#pragma once
#include "../BusinessManager.h"
#include "pch.h"
#include "Client.h"
class ClientManager {
private:
static std::shared_ptr currentClient;
MongoDBDataManager& dbManager;
AppContext& appCtx;
public:
ClientManager(AppContext& appCtx) : appCtx(appCtx), dbManager(appCtx.dbMgr) {} // this is breaking due to appctx db is not working
static void setClient(std::shared_ptr client);
static std::shared_ptr getCurClient();
static void clear();
static std::unordered_map fetchBizClients();
bool chooseAClient();
};
Может быть что-то связано с классами, которыми я здесь не поделился, я не уверен, все было хорошо, пока я не попытался облегчить себе жизнь. Должен ли я использовать что-то вроде контекста приложения?
Подробнее здесь: https://stackoverflow.com/questions/796 ... nd-declare
Мобильная версия