Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h3>Declared but did not define a variable or function.</h3> <p>A typical variable declaration is</p> <pre><code>extern int x; </code></pre> <p>As this is only a declaration, a <strong>single definition</strong> is needed. A corresponding definition would be:</p> <pre><code>int x; </code></pre> <p>For example, the following would generate an error:</p> <pre><code>extern int x; int main() { x = 0; } //int x; // uncomment this line for successful definition </code></pre> <p>Similar remarks apply to functions. Declaring a function without defining it leads to the error:</p> <pre><code>void foo(); // declaration only int main() { foo(); } //void foo() {} //uncomment this line for successful definition </code></pre> <p>Be careful that the function you implement exactly matches the one you declared. For example, you may have mismatched cv-qualifiers:</p> <pre><code>void foo(int&amp; x); int main() { int x; foo(x); } void foo(const int&amp; x) {} //different function, doesn't provide a definition //for void foo(int&amp; x) </code></pre> <p>Other examples of mismatches include</p> <ul> <li>Function/variable declared in one namespace, defined in another.</li> <li>Function/variable declared as class member, defined as global (or vice versa).</li> <li>Function return type, parameter number and types, and calling convention do not all exactly agree.</li> </ul> <p>The error message from the compiler will often give you the full declaration of the variable or function that was declared but never defined. Compare it closely to the definition you provided. <em>Make sure every detail matches.</em></p>
 

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