When I was reading <windows core programming>, I saw a strange overload:
Operator proc *()
At that time, I didn't know much about C ++. I found this method confusing for a long time. There were no parameters, no returned values, and some types of destructor.
With a strange operator keyword, it must be related to operator overloading.
Later I learned that it is actually used for type conversion. It defines the behavior and result of this class when the forced type is converted to a certain type.
Class Con { Public : Operator Const Char *() Const { Return " Hello World " ;} Con VaR ; Const Char * STR = ( Const Char *) VaR ; Cout <STR < Endl; // Hello world.
This method is useful in some cases, but generally it is not used much.
I have never been too interested in these skills. I vaguely think that type conversion should be avoided in the object-oriented world. Isn't such a style different?
In short, the name is not authentic, do not use it.
A few days ago, I saw an article about the oldArticle: Http://www.drdobbs.com/cpp/generic-change-the-way-you-write-excepti/184403758? Pgno = 3
This section describes the concepts and implementation of scopegard, which is widely referenced later.
The following section is written when the reference operation is implemented:Code:
template class T> class refholder {T & ref _; Public : refholder (T & ref ): ref _ ( ref ) {} operator T & () const { return ref _ ;}; template class T> inline refholder
byref (T &
T) {
return refholder
(t) ;}
This line:
OperatorT &()Const
Let me crack my head again while reading the code.
I suddenly remembered the reference-related things I saw when I looked at boost cmd_ptr not long ago. It was very vague and now it's on.
In some aspects, technologies are actually the same.
The skills on the other side may be infatuated, or mistaken, depending on who is using them.