Edit Updated Code:
class Any
{
public:
Any()
{
}
Any(const Any &other)
{
}
Any(Any &other) // added per Ben's answer
{
}
Any(Any &&other)
{
}
Any(const char *value)
{
}
template<typename T>
Any(const T &value)
{
}
template<typename T>
Any(T &&value)
{
cout << "move ctor" << endl;
}
template<typename T>
Any(const vector<T> &value)
{
}
template<typename T>
Any(vector<T> &&value)
{
}
};
int main(int argc, char *argv[])
{
vector<string> numbers;
numbers.push_back("one");
numbers.push_back("two");
numbers.push_back("three");
numbers.push_back("four");
Any anyNumbers(numbers);
Any anyNumbersCopy = anyNumbers;
return 0;
}
prints:
"move ctor"
Why is this happening?
Is there any way to force the default copy constructor to be called instead of the templated const& constructor?
I would like to avoid making the template constructor explicit if possible so that I can still implicitly construct the class like this;
Any number = 5;