girlcode
girlcode

Reputation: 3265

Deque using custom class cannot push_back

I am getting the following error when attempting to push_back a new custom object:

prog7.cpp:66: error: no matching function for call to 
    ‘std::deque<Job, std::allocator<Job>     >::push_back(Job*)’
    /usr/include/c++/4.4/bits/stl_deque.h:1201: note: candidates 
    are: void std::deque<_Tp, _Alloc>::push_back(const _Tp&) 
    [with _Tp = Job, _Alloc = std::allocator<Job>]

Relevant code is here:

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

Am I doing something wrong here?

Upvotes: 0

Views: 1071

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 476950

Say this:

jobs.push_back(Job());         // copy from a default-initialized object

Or:

jobs.emplace_back();           // direct-initialize a new object

Upvotes: 3

Related Questions