使用自定义类的Deque不能push_back

时间:2013-05-02 22:19:33

标签: c++ deque

尝试push_back新的自定义对象时出现以下错误:

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>]

相关代码在这里:

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

我在这里做错了吗?

1 个答案:

答案 0 :(得分:3)

说出来:

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

或者:

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