There are really two issues here:
1) The copy-assignment operator you've defined doesn't get called. The line
Student dst=src;
doesn't call the copy-assignment operator! It calls the copy constructor, which is defined implicitly by the compiler. However, if you wrote
Student dst;
dst = src;
then operator=
would be called.
2) Yes, the purpose is to avoid copying. When you call a function, including operator=
, which takes a Student
by value, the Student
object argument has to be copied (through an implicit call to the copy constructor). If the function takes a reference, on the other hand, then no copy is made.