Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Templates Error: no matching function for call
    text
    copied!<p>I get the error mentioned here: <a href="https://stackoverflow.com/questions/11052027/c-templates-error-no-matching-function-for-call-stdvectorint-stdallocat">C++ Templates Error: no matching function for call std::vector&lt;int, std::allocator&lt;int&gt; &gt;</a></p> <p>Here is the error(again):</p> <pre><code>main.cpp: In function ‘int main()’: main.cpp:21:21: error: no matching function for call to ‘Test&lt;int&gt;::foo(std::vector&lt;int, std::allocator&lt;int&gt; &gt;)’ main.cpp:21:21: note: candidate is: main.cpp:14:6: note: void Test&lt;T&gt;::foo(std::vector&lt;T&gt;&amp;) [with T = int] main.cpp:14:6: note: no known conversion for argument 1 from ‘std::vector&lt;int, std::allocator&lt;int&gt; &gt;’ to ‘std::vector&lt;int, std::allocator&lt;int&gt; &gt;&amp;’ </code></pre> <p>The problem is that I have a more complex situation and I don't know how to solve it (without breaking too much code). I have a Binary Search Tree class that is generic. I want to populate a vector of elements of type T(generic) with all the values from the binary search tree nodes - so I can't make the vector const. The function that traverses the tree is recursive.</p> <p>So I have:</p> <pre><code>/*main*/ BST&lt;int&gt; t; t.add(21); t.add(12); //.... etc. vector&lt;int&gt; elements; t.inorder(elements); /* ------------ */ </code></pre> <p>and:</p> <pre><code>/*BST.h*/ template&lt;typename T&gt; class BST{ //.... Node&lt;T&gt;* root; //.... void inorder_rec(Node&lt;T&gt;* root, vector&lt;T&gt;&amp; result); void inorder(vector&lt;T&gt;&amp; result); //.... }; template&lt;typename T&gt; void BST&lt;T&gt;::inorder_rec(Node&lt;T&gt;* root, vector&lt;T&gt;&amp; result){ // recursive call for the child nodes } void BST&lt;T&gt;::inorder(vector&lt;T&gt;&amp; result){ inorder_rec(this-&gt;root, result); } /* ------------ */ </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