Microsoft KB Archive/309700

= FIX: C2784 Error When You Try to Compile a Template Function That Takes a Function Reference =

Article ID: 309700

Article Last Modified on 4/11/2003

-

APPLIES TO


 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q309700



SYMPTOMS
The compiler generates a C2784 error when you try to create an instance of a template function that takes a function reference as an argument.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual C++ .NET (2003).



MORE INFORMATION
To reproduce this problem, try to build the following sample code: using namespace std;
 * 1) include

void func1( int (&fn)( float ) ) { cout << &quot;hello&quot; << endl; }

template void func2( R (&fn)( T ) ) { cout << &quot;goodbye&quot; << endl; }

int myfunc( float ) { return 0; }

int main {   func1( myfunc ); // works fine func2( myfunc ); // fails with C2784 return 0; } To work around this problem, use a function pointer instead of a function reference in the template definition. For example: template void func2( R (*fn)( T ) ) {cout << &quot;goodbye&quot; << endl; }

Keywords: kbbug kbfix kbpending KB309700

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.