MATLAB Object-Oriented Programming

(Joyce) #1

tf = true;
else
tf = false;
end
end
end
end


Using a double converter enables you to add numeric values to Adder objects and to
perform addition on objects of the class.


a = Adder(1:10)


a =


Adder with properties:


NumericData: [1 2 3 4 5 6 7 8 9 10]


Add two objects:


a + a


ans =


Adder with properties:


NumericData: [2 4 6 8 10 12 14 16 18 20]


Add an object with any value that can be cast to double:


b = uint8(255) + a


b =


Adder with properties:


NumericData: [256 257 258 259 260 261 262 263 264 265]


Compare objects a and b using the < operator:


a < b


ans =


1


Operator Overloading
Free download pdf