Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make this specialized function work
    primarykey
    data
    text
    <p>Here's the deal. I've looked on this forum and I didn't find the information I'm searching for or I'm probably not able to repeat it for my problem. I have a class Table which is generic and I have a class named MyString.</p> <pre><code>template &lt;typename typeGen, int DIM&gt; class Table { public: TableauGenerique() : index_(0) { //On initialise courant à 0 } void add(typeGen type); private: typeGen tableGen_[DIM]; int index_; }; </code></pre> <p>My problem is with the add function. I sometimes have to do this in the main.cpp: (which works well)</p> <pre><code> Table &lt;float,6&gt; tabFloat; tabFloat.add(1.6564); </code></pre> <p>and at one point, I need to do this which doesn't work because I need to specialize the add function to create an object of MyString, to pass it the string and then store the object in the array (tableGen) :</p> <pre><code>TableauGenerique &lt;MyString,4&gt; tabString; </code></pre> <p>So I tried this (after the class), without success.</p> <pre><code>template &lt;typename typeGen, int DIM&gt; void Table&lt;typeGen,DIM&gt;::add(typeGen type){ //Which is the generic one for float or ints if(index_ &lt; DIM) { tableGen_[courant_] = type; index_++; } } template &lt;class typeGen, int DIM&gt; void Table&lt;typeGen,DIM&gt;::add&lt;string&gt;(typeGen type) { //(line 75) Which is the specific or specialized function for myString MyString str(type); if(index_ &lt; DIM) { tableGen_[courant_] = str; index_++; } } </code></pre> <p>So, How can I make this work because it doesn't compile at all, saying: line75 : error: expected initializer before '&lt;' token and in the main it says not matching function to call Table::add(const char[6]), </p> <p>I hope everything is clear enough. Let me know if somethings is unclear.</p> <p>Thank you very much for your help !</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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