In the following snippet, I left the template the absolute placeholder in the return type assignment operator (operator =). In both cases where I have specified the template parameter or not, the code runs just fine, just wondering why?
Thanks
#include & lt; Iostream & gt; Using std :: cout; Using the Std :: endl; Square ref {int _ref_counter; Public: Ref: (): _ref_counter (0) {} zero upRef () {_ref_counter ++; } Intrusion Reef () {Return - _ Refacture; }}; Template & lt; Typename T1 & gt; Class SmartPoint {T1 * _ptr; Ref * _ref; Public: Smartporter (): _ptr (0) {_ref = New Ref ()); _ref- & gt; UpRef (); } SmartPoint (T1 * PTR): _ptr (ptr) {_ref = new ref ()); _ref- & gt; UpRef (); } SmartPonitor (Constant SmartPonter and SP): _ptr (sp._ptr), _rf (sp._ref) {{_ref-> Apfar (); } // SmartPointer & lt; T1 & gt; & Amp; Operator = (Constant SmartPonter & SP) SmartPoint & amp; Operator = (Constt Smart Pointer & SP) {// Always check the self Assignment if (this! = & Amp;); // Lose current SmartPontor information (0 == _ref-> DownRuff ()) {delete _ptr; Delete _ref; } _ptr = sp._ptr; _ref = sp._ref; _ref- & gt; UpRef (); } Return * This; } ~ SmartPonter () {if (0 == _ref-> Downfront ()) {delete _ptr; Delete _ref; }} T1 & amp; Operator * () {return * _ptr; } T1 * operator-> () {Return_ptr; }}; Class lock {public: some functions (from zero) {cout & lt; & Lt; "Called a job!" & Lt; & Lt; Endl; } ~ Lock () {cout & lt; & Lt; "Called the Destructor Lock!" & Lt; & Lt; Endl; }}; Int main () {SmartPointer & lt; Lock & gt; Peel lock (new lock ()); PMemLock- & gt; Somefuntion (); {SmartPoint & lt; Lock & gt; PMemLock1 (pMemLock); } SmartPointer & lt; Lock & gt; PMemLock2; PMemLock2 = pMemLock; PMemLock2- & gt; Somefuntion (); }
[n3690: 14.6.1 / 1] by standard:
Like normal (non-templates) sections, class templates contain injection-class-names (9 clauses). The in-class class name can be used as a template-name or a type-name. When it is used with a template-logic, then in the form of template-logic for template-templates, or as a final identifier in the extended type specifier of the Friend class templates declaration, this class template itself Otherwise, this is equivalent to the template-name, which is & lt;>.
Comments
Post a Comment