girlcode
girlcode

Reputation: 3265

Assign new custom object from deque c++

I currently have:

deque<Job> jobs;
jobs.push_back(Job(1));

Where Job is a custom class I made (really simple, just has a job number), and what I want to do is the following:

Job currentJob = jobs.pop_front();

However, this gives me errors. How do I accomplish assigning the popped Job to a new Job?

Upvotes: 1

Views: 384

Answers (2)

John Bandela
John Bandela

Reputation: 2436

What you want is this

Job currentJob = jobs.front();
jobs.pop_front();

Upvotes: 1

taocp
taocp

Reputation: 23654

Quoting from documentation:

void pop_front();

Delete first element Removes the first element in the deque container, effectively reducing its size by one.

This destroys the removed element.

 pop_front()

destroys the object, you may need to try:

Job currentJob = jobs.front();
jobs.pop_front(); //remove the object from container and reduce size by 1

See std::deque::pop_front for more information.

Upvotes: 7

Related Questions