FIX: Error C2783 - Cannot Deduce Non-Type Template Parameter

This article was previously published under Q165803
This article has been archived. It is offered "as is" and will no longer be updated.
The sample code in the MORE INFORMATION section causes the compiler errorC2783:
'declaration' : could not deduce template argument for 'identifier'
The workaround is to avoid argument deduction by specifying the template-parameter-list when calling the function template.
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Microsoft Visual C++ version 6.0.
The following sample code demonstrates the problem and the workaround:


      /* Compile options needed: none      */       template <int I>      struct C      {          int a[I] ;      };      template <int I>      int F(C<I> a)      {          return I ;      }      int main ()      {          int i;          C<4>  CObj ;          i  = F(CObj);          // Workaround: Comment the line above.          // Uncomment the following line          // i = F<4>(CObj);          return 0 ;      }				

Article ID: 165803 - Last Review: 01/09/2015 06:29:21 - Revision: 1.1

  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • kbnosurvey kbarchive kbbug kbfix kbnoupdate kbvc600fix KB165803