You are here:

C++/STD queue question

Advertisement


Question
Hello We are using a queue of queues in the following shape:

A queue of structures in SDT.  I am adding to the queue the values but when I want to erase a given structure I cannot do it because in the four item I obtain a memory crash (access violation).

the following is the piece of code:

for (int i=0;i<datasize;i++)
{
datatempsize = m_QueueToSend.front().data.size();
strcpy(datatemp.ip,m_QueueToSend.front().ip);
datatemp.priority = m_QueueToSend.front().priority;
for (int j=0; j<datatempsize; j++)
{
  datatemp.data.push(m_QueueToSend.front().data.front());
  //if (j != (datatempsize-1))
  m_QueueToSend.front().data.pop();
}          
buffer->push_back(datatemp);
m_QueueToSend.pop();

for (int h=0; h<datatempsize;h++)
  datatemp.data.pop();
}

Thanks for your help.

Answer
ana, Thank you for your question.

I don't use STL myself so I can't advise you on this issue.

You might try single-stepping through the code in your debugger.

I suggest that you post this question at www.experts-exchange.com, which is more advanced than allexperts.com.

David Spector

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


David Spector

Expertise

Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.

Experience

I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Publications
Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

Education/Credentials
ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 About.com. All rights reserved.