博客搬家,原地址:https://langzi989.github.io/2017/03/21/why-assigment-operator-can-not-be-frined-function/
this is a problem in my work and I have find th solution on stackoverflow,so recorder here
problem description
When I refactor my object, I have a problem which need to change the return value
of and function std::string to a struct data, but I don’t want to change my code
where the function be used, so I want to overload the assignment operator which
will assign a struct to string.The code is as follows:
#include <string>
class data_struct{
friend std::string operator = (std::string& s, data_struct& d);
private:
bool success{
false};
std::string message{
""};
public: