Article ID: 112985 - Last Review: July 5, 2005 - Revision: 1.1 FIX: new Allocates 0 Bytes for Typedef Class Function PointerThis article was previously published under Q112985 On This PageSYMPTOMS
Using the new operator to dynamically allocate memory for a typedef pointer
to a class member function that has return type void will allocate 0 (zero)
bytes for the function pointer.
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This problem was corrected in Microsoft Visual C++ .NET. MORE INFORMATION
When typecasting a pointer to a class member function that returns type
void and trying to dynamically allocate pointers to this user defined type,
the compiler allocates 0 (zero) bytes. This can best be seen by generating a
mixed source/assembly language listing file using the /Fc compiler option
and observing that the new operator is passed 0 bytes as the amount of
memory to allocate. Using the sample code below, the following is the
source/assembly listing for the call to new:
To work around this problem, allocate an array of chars using the sizeof() keyword to cause the new operator to allocate the proper number of bytes. The returned pointer will need to be typecast to the proper type. The following code sample demonstrates the problem and workaround: Sample Code | Article Translations
|
Back to the top
