"opperator= should takes a parametor of the (of course,const best) ref of src obj",i see this in many books,but i try to use non-ref instead,it also works!so,whats the purpose of using ref?is it just to avoid copy from the param? my test code are,
#include <iostream>
#include <string>
using namespace std;
class Student{
public:
Student& operator=(Student);
string name;
int num;
};
Student& Student::operator=(Student s)
{
name=s.name;
num=s.num;
return *this;
}
int main(){
Student src;
src.name="haha";
src.num=11;
cout<<src.name<<" "<<src.num<<endl;
Student dst=src;
cout<<src.name<<" "<<src.num<<endl;
}