c++vectoroperator-overloadingpush-back

Is using the overloading << operator as push_back a good idea?


I've been practicing with operator overloading in order to comprehend it better and I came across using the << operator with vectors like this:

void operator<<(std::vector<int> &vector, int value){
    vetor.push_back(value);
}

Now I know that this isn't really a good idea and that I should avoid doing this but I'd like to listen to someone more experienced in the subject in order to help me understand the << operator and the ostream class in a better way.


Solution

  • Now I know that this isn't really a good idea and that I should avoid doing this

    Your knowledge is correct. There are two issues with this: