Why is sorting a non-member function in classes while sorting an array of objects? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is sorting a non-member function in classes while sorting an array of objects?

I'm having problem while sorting an array of objects in classes. It's a bit confusing. If someone can help me with examples, it would be really helpful.

2nd Jul 2016, 8:18 PM
Nimesh Shahdadpuri
Nimesh Shahdadpuri - avatar
2 Answers
0
u can create an array object of the class you want to sort . Then , u can sort them the specific data member u you want to just like sorting an array . u can create a friend function which can directly access private members ( if data members u want to sort are private ) .
3rd Jul 2016, 3:09 PM
shubham sharma
0
5th Jul 2016, 11:35 AM
John Zhou
John Zhou - avatar