Can I overload existing function/operator in existing class?
I was trying to do:
#include <iostream>
#include <string>
using namespace std;
string& string::operator<<(const string& str) {
this->append(str);
}
But this gives me error:
test.cpp:5: error: too few template-parameter-lists
How can I do this? Or I can’t?
You can’t add member functions to a class unless you modify that class’ definition. Use a free function instead: