The information in this article applies to:
SYMPTOMS
The compiler does not generate any compiler errors when a non-static member
function is used as a callback function and the calling convention for the
function is explicitly specified. For example, the sample code shown in
this article will not cause the compiler to generate any compiler errors
although it should.
RESOLUTIONBy design, a member function used as a callback function must be static. A non-static member function cannot be used as a callback function. You can also use file scope global functions for callback functions. STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ version 5.0. MORE INFORMATIONUsing a non-static member function as a callback function should trigger the compiler to generate the following error when the callback function is invoked: In C++ every callback function has its own prototype, which determines the parameters that the calling function can pass to the function. However, C++ member functions have a hidden parameter known as the 'this' pointer. C++ is able to associate a function with a particular instance of an object by means of the 'this' pointer. Therefore, if a callback function, defined as a non-static member function, is called, it will expect a particular instance of an object. On the first line of the Test::Test_Func() member function in the following sample code, there is no object instance when the callback function is invoked, so a C2643 compiler error should be generated. For more information on writing C++ callback functions, please see the article "Calling All Members: Member Functions as Callbacks" on the Microsoft Development Network (MSDN) CD-ROM. Sample Code to Reproduce Problem
Additional query words:
Keywords : kbcode kbprg kbCompiler kbVC410bug kbVC420bug kbVC500fix |
Last Reviewed: September 10, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |