Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is highly dependent on the compiler and platform you are using and without actually seeing the tests I can only guess of what is going on.<br /><br /> I see some misconceptions in your code:<br /> 1) You are missing a copy operator and copy constructor You are copying the instances that contain <code>std::string</code> which might be implemented using reference counting. The reference counting is implemented in overloaded copy constructor/operator of <code>std::string</code> but these might not get called from the implicitly generated copy constructor of your class and therefore causing double freed memory and other nasty things. The copy operator/constructor should look like this:</p> <pre><code>// Copy constructor Parms(const Parms&amp; oth) { parm1 = oth.parm1; parm2 = oth.parm2; } // Copy operator Parms&amp; operator= (const Parms&amp; oth) { if (&amp;oth == this) // Check for self-assignment return *this; parm1 = oth.parm1; parm2 = oth.parm2; return *this; } </code></pre> <p><br /><br /> 2) I don't quite understand the presence of <code>value1</code> and <code>value2</code>. It seems you never initialize them, you just use them in the default constructor to copy their (empty) content into <code>parm1</code> and <code>parm2</code>. You can avoid this completely as <code>parm1</code> and <code>parm2</code> are initialized automatically to an empty string when called. <br /><br /> 3) You do not need to use the singleton pattern here. The <code>getDefaults()</code> method could be implemented as follows:</p> <pre><code>static Parms getParms() { return Parms(); } </code></pre> <p>The singleton pattern is meant for classes that only have one instance through the whole program run which doesn't seem to be the case of your class.</p> <p>This way you can safely use the <code>getParms()</code> function from multiple threads and a smart compiler will optimize out the implied additional copy.</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.
 

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