开发者

C++ queue - simple example

I can't find simple example how to use queues in C++ for pointers to some myclass objects. I have code like this:

class myclass{
  string s;
};

myclass *p = new myclass();

my_queue.push(p);

//something....

p = my_queue.front();
my_queue.pop();

std::cout << p->s;

What should be declaration of my_queue? Should I use queue or another data structure?

I need c+开发者_如何学运维+ just for small program, thanks for answers.


Simply declare it as below if you want to us the STL queue container.

std::queue<myclass*> my_queue;


std::queue<myclass*> my_queue; will do the job.

See here for more information on this container.


std::queue<myclass*> that's it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜