Export (0) Print
Expand All
Expand Minimize

Compiler Error C2785

Error Message

'declaration1' and 'declaration2' have different return types

The return type of function template specialization differs from the return type of the primary function template.

Check all specializations of the function template for consistency.

The following sample generates C2785:

// C2785.cpp
// compile with: /c
template<class T> void f(T);

template<> int f(int); // C2785
template<> void f(int); // OK

The following sample generates C2785:

// C2785_b.cpp
// compile with: /c
template <int u>
class A {
public:
   typedef void T;
};
 
class B {
public:
   template <typename C>
   typename C::T func (const C &);
};
 
template <typename C>
typename C::T B::func (const C &) {}
 
template
A<2>::T
B::func (const A<2> &);   // C2785
// try the following line instead
// B::func<A<2> >(const A<2> &);

Community Additions

ADD
Show:
© 2014 Microsoft