Re: Compiler Bug? (Relating to Pointer to Member)

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Mon, 5 Dec 2005 21:31:19 -0700, "Jonathan Wood" <jwood@xxxxxxxxxxxxxxxx>
wrote:

>I'm looking at what appears to be a compiler bug. I'm not at liberty to post
>full classes, etc. but will post the relevant pieces.
>
>Project A is a library (LIB). In that project, I define a pointer to member
>type like this:
>
>class CFileWin;
>class CFileIterator;
>typedef void (CFileWin::*LPITERATEFILEFN)(CFileIterator *);

Look at the /vmg options. And then you should probably forget about them,
because you shouldn't require library users to play around with that
option. To see the difference the presence of the class definition can
make, try this program:

#include <stdio.h>

#if 1
class CFileWin;
#else
class CFileWin
{
};
#endif

class CFileIterator;
typedef void (CFileWin::*LPITERATEFILEFN)(CFileIterator *);

int main()
{
printf("%d\n", (int) sizeof(LPITERATEFILEFN));
}

With CFileWin incomplete, the PTM size is 16. With it completed, the size
is 4. The best solution is to define a class before declaring pointers to
its members.

--
Doug Harrison
Visual C++ MVP
.