c++ - How to access a member variable of a class even after class destruction? -


i have question regarding usage of member variable of class. suppose, have class abc , have member variable buffer declared public within class, how can use variable buffer after class has been destroyed?

can declare variable buffer static? allow me access variable after class has been destroyed?

perhaps examples help.

class abc { public:     std::queue<int> buffer; }; // of above class  void foo() {     {         abc c; // c instance of class abc.  c          //object created class abc         c.buffer.push_back(0); // can change public members of c     }     // c destroyed.  not exist.  there nothing access     // abc still exists.  class has not been destroyed } 

but, here's possibility:

void foo() {     std::queue<int> localbuffer;     {         abc c; // c instance of class abc.  c          //object created class abc         c.buffer.push_back(0); // can change public members of c         localbuffer = c.buffer;     }     // c destroyed.  not exist.  there nothing access     // abc still exists.  class has not been destroyed     // localbuffer still exists, , contains information of c.buffer. } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -