Why ‘&’ reference in not required in classes in C++?

First of all you are not calling your class swap() function, because you are not calling it with your class object s, for class swap() function you have to call it with s. like

s.swap(c,d);

Further Change your function swap() name to any other name like mySwap() then you’ll get to know that this is not correct, because swap() is a built-in function of std::
so it will be simple to understand if you change the name of your function.

Furthermore, you are not using class member variables correctly, you have to do something with your class member variables a and b. your class is useless here.

Leave a Comment