title: Why C++ implicit type conversion work's well with structures but in other way with classes
body: <p>I'm trying to create a multi-dimensional array with dynamic memory initialisation in C++, but an implicit type conversion works in one way when I work directly with functions, but in another way when I tried to create class-shell around this pointer and named functions as class members.</p>
  
  <p>If template type T, for example, int, with structures it prefers (T *&amp;) type over (T &amp;) for a pointer of any nesting, but when I made these functions class members, they even can't implicitly make T** to (T*&amp;) transformation.</p>
  
  <p>I understand that T***, for instance, is not T&amp;, but empty body function is a bottom of my recursion, that initializes n-dimensional array(pointer, whatever). This conversion works with non-class functions but doesn't work implicitly with clas-member functions.</p>
  
  <pre><code>template&lt;typename T, size_t N&gt;
  struct NDimensionalArray {
      typedef typename NDimensionalArray&lt;T, N - 1&gt;::type * type;
  };
  
  template&lt;typename T&gt;
  struct NDimensionalArray&lt;T, 1&gt; {
      typedef T * type;
  };
  
  template&lt;typename T&gt;
  void initializeNDimensionalArray(T &amp;, size_t) { }
  
  template&lt;typename T&gt;
  void initializeNDimensionalArray(T *&amp; arr, size_t n) {
      arr = new T[n];
      for (size_t i = 0; i &lt; n; ++i)
          initializeNDimensionalArray(arr[i], n);
  }
  
  int main() {
  
      NDimensionalArray&lt;int, 3&gt;::type arr;
      initializeNDimensionalArray(arr, 2);
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>template &lt;typename T, size_t N&gt;
  class NDimArray {
  public:
  
          typename NDimensionalArray&lt;T, N&gt;::type arr{ nullptr };
  
          NDimArray&lt;T, N&gt;::NDimArray() {
             init(arr, 0); //exception, cannot transform T*** to T*&amp;, 
                           //invokes T&amp;                                               
          }
  
          void init(T &amp;, size_t, int) { }
  
          void NDimArray&lt;T, N&gt;::init(T *&amp; arr, size_t n) {
  
             arr = new T[n];
  
             for (size_t i = 0; i &lt; n; ++i)
                  init(arr[i], n);
          }
  
  }
  
  int main() {
      NDimArray&lt;int, 3&gt; arr(2);
  }
  </code></pre>