#include <iostream>
#include <vector>
class cell
{
private:
int m_value;
public:
void clear() {m_value = 0;}
cell(int i = 0): m_value(i) {}
cell(const cell&& move): m_value(move.m_value) {} //move constructor
cell& operator= (const cell& copy)
{
if (© == this) return *this;
clear();
m_value = copy.m_value;
return *this;
}
int getValue() const {return m_value;}
};
int main()
{
cell mycell {3}; // initializes correctly
std::vector<cell> myVec {1, 2, 3, 4}; // compile error.
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgpjbGFzcyBjZWxsCnsKcHJpdmF0ZToKaW50IG1fdmFsdWU7CnB1YmxpYzoKICB2b2lkIGNsZWFyKCkgIHttX3ZhbHVlID0gMDt9CiAgY2VsbChpbnQgaSA9IDApOiBtX3ZhbHVlKGkpIHt9CiAgY2VsbChjb25zdCBjZWxsJiYgbW92ZSk6IG1fdmFsdWUobW92ZS5tX3ZhbHVlKSB7fSAvL21vdmUgY29uc3RydWN0b3IKICBjZWxsJiBvcGVyYXRvcj0gKGNvbnN0IGNlbGwmIGNvcHkpCiAgewogICAgaWYgKCZjb3B5ID09IHRoaXMpIHJldHVybiAqdGhpczsKICAgIGNsZWFyKCk7CiAgICBtX3ZhbHVlID0gY29weS5tX3ZhbHVlOwogICAgcmV0dXJuICp0aGlzOwogIH0KICBpbnQgZ2V0VmFsdWUoKSBjb25zdCB7cmV0dXJuIG1fdmFsdWU7fQp9OwoKaW50IG1haW4oKQp7CmNlbGwgbXljZWxsIHszfTsgLy8gaW5pdGlhbGl6ZXMgY29ycmVjdGx5CnN0ZDo6dmVjdG9yPGNlbGw+IG15VmVjIHsxLCAyLCAzLCA0fTsgLy8gY29tcGlsZSBlcnJvci4KcmV0dXJuIDA7Cn0=
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
^~~~