I want to define a move constructor on a class that will be instantiated in a std::vector. However, the move constructor seems to interfere with the initialization of the vector.
#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;
}
I have done quite a bit of research but haven't been able to find the solution to this problem. Quite new to C++ programming.
edit: my class will eventually have a lot more than m_value in it, including some non-fundamental types, hence I don't want to use the default copy constructor.