How do I specify the type of a map used with a template?
<p>I first have this simple example that works (my first time using maps). The type of the name-value pairs is a string to a function pointer respectively.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;map&gt;
using std::cout;

int foo() {
    return 243;
}

int main() {

    std::map&lt;std::string, int (*)()&gt; list;

    list["a"] = foo;

    cout &lt;&lt; list["a"](); // 243

}
</code></pre>

<p>Then I tried using a template to specify the type. Where it says <code>int</code> in the map instantiation is where I'd like to specify the type using a template. So I tried but I don't exactly know where to put <code>&lt;int&gt;</code> where I'm either calling the function or making the name-value pairs. This is what I tried:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;map&gt;
using std::cout;

int foo() {
    return 243;
}

int main() {

    template &lt;typename N&gt;
    std::map&lt;std::string, N (*)()&gt; list;

    list["A"] = &lt;int&gt; foo; // right here where you see &lt;int&gt;

    cout &lt;&lt; list["A"]();

}
</code></pre>

<p>This doesn't work because I don't think I'm putting <code>&lt;int&gt;</code> in the right place. The errors I'm getting are:</p>

<pre><code>/tmp/134535385811595.cpp: In function 'int main()':
/tmp/134535385811595.cpp:11: error: expected primary-expression before 'template'
/tmp/134535385811595.cpp:11: error: expected `;' before 'template'
/tmp/134535385811595.cpp:14: error: 'list' was not declared in this scope
/tmp/134535385811595.cpp:14: error: expected primary-expression before '&lt;' token
/tmp/134535385811595.cpp:14: error: 'N' was not declared in this scope
</code></pre>

<p>Can anyone help?</p>
