Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>MyClass&lt;2&gt; a(vector&lt;float&gt;()); </code></pre> <p>This is not a variable declaration. It is the declaration of a function named <code>a</code> that returns a <code>MyClass&lt;2&gt;</code> object and takes as an argument a "pointer to a function that takes no arguments and returns a <code>vector&lt;float&gt;</code>." Confusing? Yes. This is what is referred to as the "most vexing parse."</p> <p>You need extra parentheses:</p> <pre><code>MyClass&lt;2&gt; a((vector&lt;float&gt;())); ^ ^ </code></pre> <p>Or, you can use copy initialization:</p> <pre><code>MyClass&lt;2&gt; a = MyClass&lt;2&gt;(vector&lt;float&gt;()); </code></pre> <p>Or, since your constructor isn't <code>explicit</code>, you could use:</p> <pre><code>MyClass&lt;2&gt; a = vector&lt;float&gt;(); </code></pre> <p>(Though, unless you mean for <code>vector&lt;float&gt;</code> objects to be implicitly convertible to <code>MyClass&lt;N&gt;</code> objects, you probably want to make this constructor <code>explicit</code>.)</p> <hr> <p>A good compiler should warn you about this sort of thing. Visual C++ warns:</p> <blockquote> <p>warning C4930: '<code>MyClass&lt;x&gt; a(std::vector&lt;_Ty&gt; (__cdecl *)(void))</code>': prototyped function not called (was a variable definition intended?)</p> </blockquote> <p>Clang warns:</p> <blockquote> <p>warning: parentheses were disambiguated as a function declarator</p> <pre><code>MyClass&lt;2&gt; a(vector&lt;float&gt;()); ^~~~~~~~~~~~~~~~~ </code></pre> </blockquote>
 

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