fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. class cell
  4. {
  5. private:
  6. int m_value;
  7. public:
  8. void clear() {m_value = 0;}
  9. cell(int i = 0): m_value(i) {}
  10. cell(const cell&& move): m_value(move.m_value) {} //move constructor
  11. cell& operator= (const cell& copy)
  12. {
  13. if (&copy == this) return *this;
  14. clear();
  15. m_value = copy.m_value;
  16. return *this;
  17. }
  18. int getValue() const {return m_value;}
  19. };
  20.  
  21. int main()
  22. {
  23. cell mycell {3}; // initializes correctly
  24. std::vector<cell> myVec {1, 2, 3, 4}; // compile error.
  25. return 0;
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/6/vector:62:0,
                 from prog.cpp:2:
/usr/include/c++/6/bits/stl_construct.h: In instantiation of ‘void std::_Construct(_T1*, _Args&& ...) [with _T1 = cell; _Args = {const cell&}]’:
/usr/include/c++/6/bits/stl_uninitialized.h:75:18:   required from ‘static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = const cell*; _ForwardIterator = cell*; bool _TrivialValueTypes = false]’
/usr/include/c++/6/bits/stl_uninitialized.h:126:15:   required from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = const cell*; _ForwardIterator = cell*]’
/usr/include/c++/6/bits/stl_uninitialized.h:281:37:   required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = const cell*; _ForwardIterator = cell*; _Tp = cell]’
/usr/include/c++/6/bits/stl_vector.h:1288:33:   required from ‘void std::vector<_Tp, _Alloc>::_M_range_initialize(_ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator = const cell*; _Tp = cell; _Alloc = std::allocator<cell>]’
/usr/include/c++/6/bits/stl_vector.h:379:2:   required from ‘std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = cell; _Alloc = std::allocator<cell>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<cell>]’
prog.cpp:24:36:   required from here
/usr/include/c++/6/bits/stl_construct.h:75:7: error: use of deleted function ‘constexpr cell::cell(const cell&)’
     { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:3:7: note: ‘constexpr cell::cell(const cell&)’ is implicitly declared as deleted because ‘cell’ declares a move constructor or move assignment operator
 class cell
       ^~~~
stdout
Standard output is empty