devxlogo

A Typesafe Way to Check the Binary Equality of Objects

A Typesafe Way to Check the Binary Equality of Objects

Define a template function as shown below:

 template IsEqual(const Obj & obj1, const Obj & obj2){ return !(memcmp ( &(obj1),&(obj2),sizeof (Obj)));}

size=3>
It will be used as follows.

 Obj a;Obj b;if (IsEqual(a,b)){	//objects are equal}

size=3>
This will make the code more readable and typesafe.

devx-admin

Share the Post: