I want to make following code work:
Mylist lst;
vector<int> v = lst;
So I see I need to convert my list into a vector.
I tried this code:
vector<int> operator=(vector<int> v, const List & l) {
return v; // more profound stuff later :-)
}
(placed it outside the class). unfortunately Visual Studio throws me: “Error: ‘operator=’ must be a member function”.
And I don’t get it – what should I do? I can’t place this function inside vector class…
Can you help me out with that?
Thanks!
You can overload the cast of your type to any other type (see this and other resources easily discoverable by Google). I think this is what you need here. Overloading the assignment operator is used for quite another thing in C++.