Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em><strong>1. C++ standard forbids using locally-defined classes with templates.</em></strong></p> <p><strong>14.3.1/2</strong>: <em>A local type, a type with no linkage, an unnamed type or a type compounded from any of these types shall not be used as a template-argument for a template type-parameter.</em></p> <p>A code example: </p> <pre><code> template &lt;class T&gt; class X { /* ... */ }; void f() { struct S { /* ... */ }; X&lt;S&gt; x3; // error: local type used as // template-argument X&lt;S*&gt; x4; // error: pointer to local type // used as template-argument } </code></pre> <p>Here is a little more reference from IBM documentation:</p> <p><em><strong>2. Declarations in a local class can only use type names, enumerations, static variables from the enclosing scope, as well as external variables and functions.</em></strong></p> <p>A Code Example: </p> <pre><code>int x; // global variable void f() // function definition { static int y; // static variable y can be used by // local class int x; // auto variable x cannot be used by // local class extern int g(); // extern function g can be used by // local class class local // local class { int g() { return x; } // error, local variable x // cannot be used by g int h() { return y; } // valid,static variable y int k() { return ::x; } // valid, global x int l() { return g(); } // valid, extern function g }; } int main() { local* z; // error: the class local is not visible return 0; } </code></pre> <p><em><strong>3. A local class cannot have static data members</em></strong></p> <p>A Code Example: </p> <pre><code>void f() { class local { int f(); // error, local class has noninline // member function int g() {return 0;} // valid, inline member function static int a; // error, static is not allowed for // local class int b; // valid, nonstatic variable }; } </code></pre>
 

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