0

尝试 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());

我在这里做错了吗?

4

1 回答 1

3

说这个:

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

或者:

jobs.emplace_back();           // direct-initialize a new object
于 2013-05-02T22:21:10.297 回答