fork(1) download
  1. #include <vector>
  2.  
  3. struct Foo{
  4. int i;
  5. };
  6.  
  7. int main() {
  8. Foo foo{42}; //fine
  9. std::vector<Foo> v;
  10. v.emplace_back(42); //not fine
  11. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/i386-linux-gnu/c++/5/bits/c++allocator.h:33:0,
                 from /usr/include/c++/5/bits/allocator.h:46,
                 from /usr/include/c++/5/vector:61,
                 from prog.cpp:1:
/usr/include/c++/5/ext/new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Foo; _Args = {int}; _Tp = Foo]':
/usr/include/c++/5/bits/alloc_traits.h:256:4:   required from 'static std::_Require<typename std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::type> std::allocator_traits<_Alloc>::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = Foo; _Args = {int}; _Alloc = std::allocator<Foo>; std::_Require<typename std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::type> = void]'
/usr/include/c++/5/bits/alloc_traits.h:402:16:   required from 'static decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) std::allocator_traits<_Alloc>::construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = Foo; _Args = {int}; _Alloc = std::allocator<Foo>; decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) = <type error>]'
/usr/include/c++/5/bits/vector.tcc:96:30:   required from 'void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int}; _Tp = Foo; _Alloc = std::allocator<Foo>]'
prog.cpp:10:19:   required from here
/usr/include/c++/5/ext/new_allocator.h:120:4: error: no matching function for call to 'Foo::Foo(int)'
  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
    ^
prog.cpp:3:8: note: candidate: Foo::Foo()
 struct Foo{
        ^
prog.cpp:3:8: note:   candidate expects 0 arguments, 1 provided
prog.cpp:3:8: note: candidate: constexpr Foo::Foo(const Foo&)
prog.cpp:3:8: note:   no known conversion for argument 1 from 'int' to 'const Foo&'
prog.cpp:3:8: note: candidate: constexpr Foo::Foo(Foo&&)
prog.cpp:3:8: note:   no known conversion for argument 1 from 'int' to 'Foo&&'
stdout
Standard output is empty