new FontFamily() new FontFamily[n]() 失败


new FontFamily失败??!! (2006-06-09 18:02)
分类:  GDI+

FontFamily *pff = new FontFamily;
error C2660: 'new' : function does not take 3 parameters
FontFamily *pff = new FontFamily[5];
error C2660: 'new[]' : function does not take 3 parameters
 
FontFamily *pff = new FontFamily(L"Asia");
error C2660: 'new' : function does not take 3 parameters
 
FontFamily *pff = new FontFamily(L"Asia")[3];
error C2660: 'new' : function does not take 3 parameters
error C2143: syntax error : missing ';' before '['
 
真不知道FontFamily类是怎么作出这种效果的
 
------------------------------------------------------------------------------------------------------------------------------------------
 
终于google出原因是:
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
详细的解释在这里:
 
核心是说DEBUG模式下有
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
 
因此new被重载为
#if defined(_DEBUG) && !defined(_AFX_NO_DEBUG_CRT)
void * AFX_CDECL  operator new (size_t nSize , LPCSTR lpszFileName ,  int nLine );
#define DEBUG_NEW new(THIS_FILE, __LINE__)
#if _MSC_VER >= 1200
void AFX_CDECL  operator delete ( void * p , LPCSTR lpszFileName ,  int nLine );
#endif
 
DEBUG_NEW默认有3个参数, 而GDI+中
class GdiplusBase
{

public
:
    void
 ( operator delete )( void * in_pVoid )
    {

       DllExports ::GdipFree (in_pVoid );
    }

    void
* ( operator new )(size_t in_size )
    {

       return
 DllExports ::GdipAlloc (in_size );
    }

    void
 ( operator delete [])( void * in_pVoid )
    {

       DllExports ::GdipFree (in_pVoid );
    }

    void
* ( operator new [])(size_t in_size )
    {

       return
 DllExports ::GdipAlloc (in_size );
    }
};

没有匹配的operator new在RELEASE模式下不会出问题(没有重载new)
要在DEBUG模式下编译通过只需给Gdiplusbase.h增加匹配的operator new
            void  * ( operator new )(size_t nSize , LPCSTR lpszFileName ,  int nLine )
            {

                return
 DllExports ::GdipAlloc (nSize );
            }


            void
 (operator delete) ( void * p , LPCSTR lpszFileName ,  int nLine )
            {

                DllExports ::GdipFree (p );
            }

              void * (operator new[])(size_t nSize, LPCSTR lpszFileName, int nLine)
            {

                return
 DllExports::GdipAlloc(nSize);
            }


            void
 (operator delete[])(void* p, LPCSTR lpszFileName, int nLine)
            {

                DllExports::GdipFree(p);
            }
------------------------------------------------------------------------------------------------------------------------------------------
 
如果 PrivateFontCollection 和 FontFamily 都是 new 出来的
delete 要先 FontFamily 后 PrivateFontCollection 否则会异常
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值