and another template expertise, which I can not solve:
terminallog.hh
// stripped code class terminology {public: terminology (); Terminallog (int); Virtual ~ terminology (); Template & lt; Class T & gt; Terminology & amp; Operator & lt; & Lt; (Const T & V); Template & lt; Class T & gt; Terminology & amp; Operator & lt; & Lt; (Const std :: vector & lt; T & gt; & amp; v); Template & lt; Class T & gt; Terminology & amp; Operator & lt; & Lt; (Cost TV []); Terminology & amp; Operator & lt; & Lt; (Const char v []); // strip code}; terminallog.hh continued (thanks for the comment edit)
// the stripped code template & lt; Class T & gt; Terminology and Terminology :: Operator & lt; & Lt; (Const T & V) {std :: cout & lt; & Lt; Std :: endl; This- & gt; letter of demand (); Std :: cout & lt; & Lt; V; Return * This; } Template & lt; Square T & gt; Terminology and Terminology :: Operator & lt; & Lt; (Const std :: vector & lt; T & gt; & amp; v) {for (unsigned int i = 0; i This is okay, no error is compiled but when I try to do this:
Terminal Clog ( 3); Int test [] = {5,6,7,8}; Stop & lt; & Lt; testing; It always prints the indicator - the address of the array. In other words, special template
Terminology & amp; Operator & lt; & Lt; (Cost TV []); It is never said that I have also verified it with an extra cot, no matter what I try, that program is always calling
Terminology & amp; Operator & lt; & Lt; (Const T & V); And there is no specialty. Obviously there should be an error in my code, although I am not getting this.
My condition is that conversion rules apply here. Since there is no exact match for int [5] (which is the real type of your array), your array will rotate with int * and const T & amp; will be chosen because it would be better match with const T v [] (which is considered as const T * v ). For the detailed explanation on overloaded resolution mechanism in this case, see @sth's answer.
If you try:
template & lt; Class T, size_t N & gt; Terminology & amp; Operator & lt; & Lt; (Const T (& amp; v) [n]); Instead?
In the definition of surcharge with the sizeof , you can not get the size like this in the format T [] is plain wrong. Again the array will decay an indicator and element always sizeof (T *) / sizeof (T) .
Comments
Post a Comment