[Solved] C++: Update to memory location using pointer is lost [closed]


This is bad:

void TestLocalQueue::putMsg(){
    ControlCommand cc;
    cc.setDynamic("target");
    cout<<"Setting Dynamic context \n"<<endl;
   localQueue->put(&cc );

The localQueue->put function stores the pointer you give it into the queue.
However cc‘s lifetime is only for the duration of the putMsg function, so when this function exits you will have a dangling pointer.

To fix this you could either make the queue store copies of objects, or you could dynamically allocate cc.

0

solved C++: Update to memory location using pointer is lost [closed]