title: How to define a constructor of a template class C with template argument float with template parameters that can be cast to float?
body: <p>I have searched for results, but the following questions are not what I want.</p>
  <blockquote>
  <ul>
  <li><a href="https://stackoverflow.com/questions/40239871/passing-object-of-a-template-class-to-constructor-of-another-class">Passing object of a template class to constructor of another class</a></li>
  </ul>
  </blockquote>
  <p>In my case, I want to define my own template matrix class</p>
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename T&gt;
  class Matrix
  {
  public:
      Matrix();
      Matrix(const Matrix&lt;T&gt;&amp;);
      template&lt;typename U&gt; Matrix(const Matrix&lt;U&gt;&amp;);
  };
  </code></pre>
  <p>I know it would be better to add constraints for T and U, but I omitted it for simplicity. When I only define the first two constructors as following, everything goes well.</p>
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename T&gt;
  Matrix&lt;T&gt;::Matrix()
  {
  
  }
  
  template&lt;typename T&gt;
  Matrix&lt;T&gt;::Matrix(const Matrix&lt;T&gt;&amp;)
  {
  
  }
  </code></pre>
  <p>How every, if I try to add a definition of the last template constructor as follows:</p>
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename T, typename U&gt;
  Matrix&lt;T&gt;::Matrix(const Matrix&lt;U&gt;&amp;)
  {
  }
  </code></pre>
  <p>The g++ complier says</p>
  <pre><code>.\test.cpp:27:1: error: no declaration matches 'Matrix&lt;T&gt;::Matrix(const Matrix&lt;U&gt;&amp;)'
     27 | Matrix&lt;T&gt;::Matrix(const Matrix&lt;U&gt;&amp;)
        | ^~~~~~~~~
  .\test.cpp:11:26: note: candidates are: 'template&lt;class T&gt; template&lt;class U&gt; Matrix&lt;T&gt;::Matrix(const Matrix&lt;U&gt;&amp;)'
     11 |     template&lt;typename U&gt; Matrix(const Matrix&lt;U&gt;&amp;);
        |                          ^~~~~~
  .\test.cpp:21:1: note:                 'Matrix&lt;T&gt;::Matrix(const Matrix&lt;T&gt;&amp;)'
     21 | Matrix&lt;T&gt;::Matrix(const Matrix&lt;T&gt;&amp;)
        | ^~~~~~~~~
  .\test.cpp:15:1: note:                 'Matrix&lt;T&gt;::Matrix()'
     15 | Matrix&lt;T&gt;::Matrix()
        | ^~~~~~~~~
  .\test.cpp:6:7: note: 'class Matrix&lt;T&gt;' defined here
      6 | class Matrix
        |       ^~~~~~
  </code></pre>
  <p>It seems like C++ trates <code>template&lt;typename T, typename U&gt;</code> and <code>template&lt;class T&gt; template&lt;class U&gt;</code> as different things. However, even if I've guessed this, I don't know exactly how to fix my code.</p>
  <p>I don't know whether I could achieve my functionality with C++ (I guess yes). Could you please show me the most practical implementation of the functionality I want?</p>