Export (0) Print
Expand All
Expand Minimize

Compiler Error C2782

Error Message

'declaration' : template parameter 'identifier' is ambiguous

The compiler cannot determine the type of a template argument.

The following sample generates C2782:

// C2782.cpp
template<typename T>
void f(T, T) {}

int main() {
   f(1, 'c');   // C2782
   // try the following line instead
   // f<int>(1, 'c');
}

C2782 can also occur when using generics:

// C2782b.cpp
// compile with: /clr
generic<typename T> void gf(T, T) { }

int main() {
   gf(1, 'c'); // C2782
   // try the following line instead
   // gf<int>(1, 'c');
}

C2782 can also occur when you specify the wrong generic type parameter:

// C2782c.cpp
// compile with: /clr
#using <System.Drawing.dll> 

using namespace System; 
using namespace System::Drawing; 
using namespace System::Collections::Generic; 

Point PointFToPoint(PointF pf) { 
   return Point((int) pf.X, (int) pf.Y); 
}; 

int main() { 
   array<PointF>^ apf = { PointF(27.8F, 32.62F) };

   array<Point>^ ap = 
      Array::ConvertAll<Point>(apf, gcnew Converter<PointF, Point>(&::PointFToPoint));   // C2782

      // try one of the following lines instead
      // Array::ConvertAll(apf, gcnew Converter<PointF, Point>(PointFToPoint));
      // Array::ConvertAll<PointF>(apf, gcnew Converter<PointF, Point>(PointFToPoint));
      // Array::ConvertAll<PointF, Point>(apf, gcnew Converter<PointF, Point>(PointFToPoint));

   for each(Point p in ap) 
      Console::WriteLine(p); 
}

Community Additions

ADD
Show:
© 2014 Microsoft