Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>CCard card; </code></pre> <p>is the way to use the default constructor.</p> <p>But your teacher is wrong, in C++ we will use free functions to extend functionalities very frenquently.</p> <p>In your case, it is wise to use the constructor because it is meant this way, except if you have special needs you don't need to do a newCard: this will generate unnecessary copies.</p> <hr> <p>"new" is reserved for pointers, so you have to use something like this:</p> <pre><code> CCard * card = new CCard(); </code></pre> <p>And you have to explicitly <code>delete</code> them. But pointers should be used only when necessary, and if possible not 'raw' but smart. (see smart pointers like boost::shared_ptr)</p> <hr> <p><strong>FOR YOUR EDIT</strong></p> <p>You can give your CCard new values using:</p> <p>-) a method of CCard like:</p> <pre><code>card.newValues(); </code></pre> <p>The constructor could also call "newValues()" to avoid being redundant.</p> <p>-) a free function (or a member of another class) that takes a CCard as a reference parameter:</p> <pre><code> void newValues( CCard &amp; card ) { /* set new values */ }; newValues( card ); </code></pre> <p>-) Directly</p> <pre><code> card.set( /*values*/ ); </code></pre> <p>Maybe with a set of accessors (set/get) if it means something for you class.</p> <p>The question you have to ask yourself is whether you want to change your class internals with accessors, or you only want to change its value inside the class.</p> <p>-) If you really want to call the constructor again, you can make a copy:</p> <pre><code> CCard c; c = CCard(); </code></pre> <p>But it's just like creating a new CCard.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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