I am trying to overload assignment operator to allow set being assigned to an unordered_set. And I have run into trouble, please help.
set<int> operator=(unordered_set<int> us)
{
set<int> s;
for(auto val:us) { s.insert(val); }
return s;
}
I get the following error:
error: ‘std::set<int> operator=(std::unordered_set<int>)’ must be a nonstatic member function
set<int> operator=(unordered_set<int> us)
This function is a global function, don't know why g++ thinks it is a static function. As a dumb solution, I add auto qualifier to the function.
set<int> auto operator=(unordered_set<int> us)
{
set<int> s;
for(auto val:us) { s.insert(val); }
return s;
}
I get the following error:
error: two or more data types in declaration of ‘operator=’
set<int> auto operator=(unordered_set<int> us)
Any ideas how do I get around this? I have tried searching a solution for this but in vain.