c++ - Template class requires template arguments? -
Sorry, I did not know how to write a great headline for this question, feel free to edit.
I have many classes that have the same role , which means that they all apply the same interface (set of methods). Consider that they all get from the same table class (even if this is not a case in a minor example, this is not the issue of this question). code> A without template logic . Internally, this new class The example that fails is: U , and one of the previous sections
A & lt; T & gt; and
a & lt; U & gt; . Is this possible? C + + 11 replies are welcome, if necessary, do not hesitate to add the tag.
#include & lt; Iostream & gt; // ------------------------------------------------ ------------------------ straight eng_tag {}; Struct fr_tag {}; Struct sp_tag {}; // First implementation of the "Talk Interface" template & lt; Class T = eng_tag> struct e {zero point () {std :: cout & lt; & Lt; "Hello \ n"; }}; Template & lt; & Gt; Structure A & lt; fr_tag & gt; {Zero point () {std :: cout & lt; & Lt; "Saluting \ n"; }}; Template & lt; & Gt; Structure A & lt; sp_tag & gt; {Zero point () {std :: cout & lt; & Lt; "Hail \ n"; }}; // Second Implementation Template & lt; Class T = eng_tag> struct b {zero point () {std :: cout & lt; & Lt; "By \ n"; }}; Template & lt; & Gt; Structure B & lt; fr_tag & gt; {void talk () {std :: cout & lt; & Lt; "A Bientot \ n"; }}; Template & lt; & Gt; Structure B & lt; Sp_tag & gt; {Zero point () {std :: cout & lt; & Lt; "Adios \ n"; }}; // e.t.c... // ------------------------------------------ ------------------------------ Templates & lt; Class T, Class U, Class I = A & gt; Structure Cover (I
A is not a type if you do not want template template parameter (,):
template & lt; Square t, square u, template & lt; typename & gt; Class I = A & gt; // ^^^^^^^^^^^^^^^^^^^^^^^^ Template Template Parameter Straight B {i
Comments
Post a Comment