Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ classes overloading: is it possible to make compiler see which one to use based on template?
    primarykey
    data
    text
    <p>I have created N classes that take from one to N ints into constructors (and I hoped that would be enough) but appeared I am wrong. </p> <p>Here are 2 sample classes:</p> <pre><code>template &lt; class T0 , class T1&gt; class my_map { typedef T0 type_0; typedef T1 type_1; std::map&lt;std::string, type_0* &gt; T0_var; std::map&lt;std::string, type_1* &gt; T1_var; friend class apitemp; public: my_map( int meaningless0 = 42 , int meaningless1 = 42 ) {} class apitemp { std::string n_; my_map* p; public: apitemp(std::string name_, my_map* parent) : n_(name_), p(parent) {} operator type_0*() {return p-&gt;T0_var[n_] ; } operator type_1*() {return p-&gt;T1_var[n_] ; } }; void insert(std::string name, type_0* ptr) { T0_var[name] = ptr; } void insert(std::string name, type_1* ptr) { T1_var[name] = ptr; } apitemp operator[](std::string n_) {return apitemp(n_, this);} }; template &lt; class T0&gt; class my_map { typedef T0 type_0; std::map&lt;std::string, type_0* &gt; T0_var; friend class apitemp; public: my_map( int meaningless0 = 42 ) {} class apitemp { std::string n_; my_map* p; public: apitemp(std::string name_, my_map* parent) : n_(name_), p(parent) {} operator type_0*() {return p-&gt;T0_var[n_] ; } }; void insert(std::string name, type_0* ptr) { T0_var[name] = ptr; } apitemp operator[](std::string n_) {return apitemp(n_, this);} }; </code></pre> <p>Order does not matter... when both classes are present I can't compile my code, when one is commented (and we use API from only one of 2 classes) everything compiles... but when I try to use both I get compiler errors... So I wonder how to make such classes overridable? </p>
    singulars
    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.
 

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