Doubt in comparator class

I don’t understand that why do we need comparator class, because if we are using a templated class T then it should also deal with string datatype ?

Also if we talk about user-defined datatype then will templated class T be able to deal with that or the only option left with us is comparator class ?

hello @yashsharma4304
system has no knowledge about user defined classes so its responsibiltiy of user to define how to perform comparision for such classes, and thats why here in the video bhaiya defining custom comparator

1 Like

But string is not user-defined class so why we are using comparator class for that ?

book is user defined , we are writing comparator for book

1 Like

Ok now it’s clear. Thanks for resolving my doubt. :slightly_smiling_face:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like