Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>handler myhandler; </code></pre> <p>That creates an object. If it's inside a function, then it has <em>automatic</em> storage duration, and will be destroyed automatically when it goes out of scope. If it's outside a function, then it has <em>static</em> storage duration, and will be destroyed automatically at the end of the program.</p> <pre><code>handler myhandler=new handler(); </code></pre> <p>That probably doesn't compile; unless <code>handler</code> has a strange constructor allowing implicit conversion from a pointer, in which case it does something strange.</p> <pre><code>handler *myhandler; </code></pre> <p>That declares a pointer, which could be used to refer to an object of type <code>handler</code>. It doesn't create an object, nor does it point to any object yet.</p> <pre><code>handler *myhandler=new handler(); </code></pre> <p>That creates a dynamic object, and initialises a pointer to point to it. This is usually a bad idea, since it's likely to lead to a <em>memory leak</em> (or worse) when you fail to delete it correctly. Don't create dynamic objects unless you really need them to outlive the current scope; and use a smart pointer when you do need to:</p> <pre><code>auto myhandler = std::make_unique&lt;handler&gt;(); // C++14 std::unique_ptr&lt;handler&gt; myhandler(new handler); // C++11 </code></pre> <p>If you really want to juggle a raw pointer for educational purposes, then remember to delete the object once you've finished with it:</p> <pre><code>delete myhandler; </code></pre> <p>and take special care to make sure this only happens once, and happens even if an exception is thrown.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      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