@OPSure. Define the + operator like writetonsharmadid, but with boolean variables rather than variables of type class x. NB: For booleans, do not pass the arguments by reference as they are intrinsic types.
EDIT: However, why exactly to you want to add booleans? This seems to me to be a counter intuitive thing to do, as they are not an arithmetic type.
EDIT EDIT: @writetonsharma Shouldn't those parameters be const?
@maory
You can add booleans (which is boolean disjunction), but in C++ it technically means something other than what you expect.
Instead of using +, just use the proper boolean operator: |.
Im building a template class of 'sparse matrix' (implemented by my LinkedList) that has += operator.
When my matrix recieves bool elements, I want the function operator+= be like AND (&&).
this is why I want to create a operator+ for boolean that will solve my problem.
You can overload any operator in c++ although I am confused as to what you will gain by a+b instead of using the standard operators, unless you want a + (and) b to mean something entirely different that what it usually means.
As pointed out by Xander, you cannot overload operators between two intrinsic data types, such as bool and bool. You could bool and SomeClass, or SomeClass and bool, but not bool and bool.
The trick is there on lines 21 and 27, where the result is cast back from an integer to a boolean.
Hence, your matrix class, so long as you immediately cast algebraic operations back to bool, needs no special handling for booleans over other integer types.