I am trying to learn more about how operator overloading works.
I understand that operator overloading with a comma may not be the best idea, but this is for educational purposes only.
I expect the following code to use my overloaded operator (I used parentheses because I know that the comma operator has the lowest priority) to build a vector containing (1,2), and then call the vector assignment operator.
However, I get the error message:
no known conversion from argument 1 from 'int' to 'const std::vector<int>&'
I do not understand why this is happening. (1,2) should build a vector, so shouldn't it try to convert from int to vector<int> ?
#include <vector> #include <utility> using std::vector; using std::move; template <typename T> vector<T> operator,(const T& v1, const T& v2) { vector<T> v; v.push_back(v1); v.push_back(v2); return move(v); } int main() { vector<int> a; a = (1,2); return 0; }
source share