I am trying to write proper c++ code, and EASY to read
i have a class for UDP traffic
untill now i have declared it as global obj and added extern to all files,
after some reading i have understoom the wat to go is Singleton class and gets pointer to it every time i want to use that class
i am tring some thing like that but i cant understand how to make it work
this is in the traficMngr.h:
class traficMngr {
public:
traficMngr();
virtual ~traficMngr();
static traficMngr *instance()
{
if (!s_instance)
s_instance = new traficMngr;
return s_instance;
}
private:
static traficMngr* s_instance;
and now every where in the code i should just do :
traficMngr* tfcMngr=traficMngr::instance();
and to use lets say send msg just do
tfcMngr->sendMsg(Buff,Size);
Is this the right way to use it? will it work at all?