Article ID: 112985
Article Last Modified on 7/5/2005
; 26 : // Try to allocate array of ptr's to ptr to member functions
; 27 : ppfVoid = new PtrVoid[10]; // Allocates zero bytes
0002e 6a 00 push 0
00030 e8 00 00 00 00 call ??2@YAPAXI@Z ; operator new
00035 83 c4 04 add esp, 4
00038 89 45 fc mov DWORD PTR _ppfVoid$[ebp], eax
This problem occurs only when using a return type of void for the typedef
pointer to class member function. Any other return type causes the proper
amount of memory to be allocated by the new operator.
/* Compile options needed: /Fc
To generate assembly/source listing */
class CTest
{
public:
void FcnVoid();
int FcnInt();
};
typedef void (CTest::*PtrVoid)(); // Defines PtrVoid as type pointer
// to member function which returns
// void.
typedef int (CTest::*PtrInt)(); // Defines PtrInt as type pointer to
// member function which returns int.
void main(void)
{
PtrVoid *ppfVoid; // Declares ppfVoid to be of type pointer to
// PtrVoid.
PtrInt *ppfInt; // Declares ppfInt to be of type pointer to
// PtrInt.
// Allocating ptr to ptr to member fcn that returns
// int works correctly.
ppfInt = new PtrInt; // Allocates correct number of bytes.
delete ppfInt;
// Try to allocate array of ptr's to ptr to member functions.
ppfVoid = new PtrVoid[10]; // Allocates 0 bytes.
delete ppfVoid;
// *** Use sizeof() to work around. ***
// Allocate correct number of bytes and cast return
// pointer to proper type.
ppfVoid = (PtrVoid*)new char[sizeof(PtrVoid)*10];
delete ppfVoid;
}
Keywords: kbbug kbfix kbnoupdate KB112985