Note that there are some explanatory texts on larger screens.

plurals
  1. PODefault variables in class with g++
    primarykey
    data
    text
    <p>I have a class which should only ever be initialized in a certain way. As part of the error checking, I have a <code>bool quality</code> which I want to have a default value of zero unless the correct constructor is called (which then checks the arguments to see whether it has been called correctly).</p> <pre><code>class CParameters { private: bool quality = 0; //Plus some additional code }; </code></pre> <p>gives me </p> <pre><code>warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default] bool quality = 0; ^ </code></pre> <p>Alternatively: </p> <pre><code>class CParameters { private: bool quality; public: CParameters; }; CParameters::CParameters { quality = 0; } </code></pre> <p>gives me the following error:</p> <pre><code>error: declaraion does not declare anything [-fpermissive] CParameters; ^ </code></pre> <p>Alternatively2: </p> <pre><code>class CParameters { private: bool quality; public: CParameters(); bool good(); }; CParameters::CParameters() { quality = 0; } bool CParameters::good() { return quality; } </code></pre> <p>and then calling it</p> <pre><code>CParameters CLI; CLI.good(); </code></pre> <p>gives this error:</p> <pre><code>error: request for member 'good' in 'CLI', which is of non-class type 'CParameters()' </code></pre> <p><strong>EDIT: The second alternative is correct. The reason CParameters() is a non-class is that I'm too dumb to actually compile parameters.cpp while compiling the other files.</strong></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