Suppose I have a class Crate
, and it has two members, width
and height
. Now suppose I want the line std::cout << myCrate << '\n';
to print this:
#---#
| |
| |
#---#
if myCrate
has width = 5
and height = 4
. Different width
s and height
s should result in different crate sizes. Can I define this behavior, e.g. through overloading the <<
operator? How would I go about doing this?
Keep in mind that this is a generic example and not specific to the Crate
class above.