Note that there are some explanatory texts on larger screens.

plurals
  1. POsingleton and classic constructor
    primarykey
    data
    text
    <p>This question is fairly fundamental.I gave a simple and straighfoward test on my cygwin:</p> <pre><code> class Example { public: Example(){ cout&lt;&lt;"dude..."&lt;&lt;endl; } ~Example(){ cout&lt;&lt;"see ya"&lt;&lt;endl; } public: static Example *GetInstance(){ if(m_instance==NULL){ m_instance = new Example(); cout&lt;&lt;"watch out bro"&lt;&lt;endl; } return m_instance; } public: void exp(){cout&lt;&lt;"greetings"&lt;&lt;endl;} private: static Example *m_instance; }; int main(){ Example a; return 0; } </code></pre> <p>Obviously,the output is:</p> <pre><code> dude... greetings see ya </code></pre> <p>Technically singleton and typical constructor are pretty much different stories in c++ programming since singleton puts constructor as private while typical way is opposite.In my recent internship experiences I have noticed that most coders implement APIs in this manner.</p> <p>I just wonder if that is the case or unnecessary when both class construction approaches exist in parallel.</p> <p><em><strong>UPDATE</em></strong></p> <p>Is constructor &amp; singleton existing in one program practically nonsense cuz singleton stuff in this scope would become useless codes like unhazardous trash?</p> <p><em><strong>SUMMARY</em></strong> This is quite a nonsense question... and what's more,thanks to all of you brilliants constructor and singleton design pattern are "mutually exclusive" and in terms of vulnerbility,it is the same story as global variables kill our debug time...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload