Something like: [pseudo code]
class DataManager
{
public:
DataManager(); // Remember to set m_customerModel etc to NULL in constructor
~DataManager();
#ifdef DEBUG
{
if (m_customerModel == NULL) throw E_NULLPOINTEREXCEPTION;
return m_customerModel;
}
#else
#endif
private:
};
DataManager *dmgr = new DataManager();
dmgr->SetCustomerModel (myModel);
[...]
myNewClass = new someclass(dmgr);
[...]
dmgr->customerModel()->doSomething(); or pass dmgr->customerModel() pointer to some other function or class.
If you added another pointer to the class and forget to call the set(), it'll just throw an exception to remind you.
class DataManager
{
public:
DataManager(); // Remember to set m_customerModel etc to NULL in constructor
~DataManager();
void SetCustomerModel(QStandardItemModel *customerModel);
void SetInvoiceModel(QStandardItemModel *invoiceModel);
#ifdef DEBUG
QStandardItemModel *customerModel()
{
if (m_customerModel == NULL) throw E_NULLPOINTEREXCEPTION;
return m_customerModel;
}
#else
inline QStandardItemModel *customerModel() {return m_customerModel};
inline QStandardItemModel *invoiceModel() {return m_invoiceModel};
#endif
private:
QStandardItemModel *m_customerModel;
QStandardItemModel *m_invoiceModel;
};
DataManager *dmgr = new DataManager();
dmgr->SetCustomerModel (myModel);
[...]
myNewClass = new someclass(dmgr);
[...]
dmgr->customerModel()->doSomething(); or pass dmgr->customerModel() pointer to some other function or class.
If you added another pointer to the class and forget to call the set(), it'll just throw an exception to remind you.
To copy to clipboard, switch view to plain text mode
Bookmarks