I want to be an operator expert & lt; & Lt; But this code is not compiled;
template & lt; & Gt; Std :: ostream & amp; For operator & lt; & Lt; & Lt; My_type & gt; (Std :: ostream & strm, my_type obj); To be an expert on a template, you must first declare a template. A free operator & lt; & Lt; In case of you do not need a template; You can overload it for your my_type category:
std :: ostream & amp; Operator & lt; & Lt; (Std :: ostream & strm, my_type obj);
If your object is not trivial in size, you may want to consider passing through a conferencing context so that you do not copy it every time you stream it:
std :: ostream & amp; Operator & lt; & Lt; (Std :: ostream & strm, const my_type & obj); (Technically you can be an expert of the operator , but I do not think this is what you want To use a template operator in general with the syntax & lt; & lt; you need to make template specialties lessenable from one of the parameter types. Example
/ / template session
)
Comments
Post a Comment