我实现在了一个类CLASS A,此类以CObject为基类,又以A为基为实现一个class B
有两个虚函数。没有在这些类中使用任何 动态内存分配。而且这些类是在动态库中实现的。
我现在在主程序中(单文档)用A *pA =  new A 动态申请了A的对像然后立即删除 delete pA;
这两句紧挨着中间没有做任何事。但是就在删除的时候出错了。
出错信息如下。program:D:\lib\Myproject.exe;
File: dbgheap.c
Line:1011Expression: _CrtIsValiHeapPointer(pUserData)For information on how your program can cause an assertion failure, see the Visual C++
documentation on asserts另外。如共享动态库有时候不会错 和 用静态动态库会出错。

解决方案 »

  1.   

    你的DLL是扩展DLL吗?只有扩展DLL才能导出类,否则,你在外面如何用类.
      

  2.   

    析构函数是virtual的 也是扩展DLL 现在是能用。只是在删除的时候出错。
    如果是 不用动态申请直接说明一个对像也不会出错。
      

  3.   

    这里同虚析构函数有什么关系啊!另外。如共享动态库有时候不会错 和 用静态动态库会出错。类正确导出了吗?
    AFX_EXT_CLASS,用工具查看下先没理由用静态链接到MFC类库会出错啊哈哈,学习
      

  4.   

    郁闷。从04年到现在,我发的几个帖都是我自己解决的。又白送了一百分。。郁闷啊。The default data member packing for structures and classes is 8 bytes. MFC headers change this to 4 bytes to save memory. Because afxdocob.h is missing the #pragma pack(pop), all user class declarations compiled after including this file will be packed with 4-byte alignment. When sharing this class between an application and an extension DLL, the structure will be packed differently since the extension DLL doesn't include afxdocob.h. Subsequent use of this class may result in invalid data or an access violation, especially when new and delete are called. 
    修改方法
    VC5.0及以后版本 主程序的 stdafx.h 中 #include <afxdocob.h>
    在5.0以前的版本中。除了主程序的 stdafx.h 中 #include <afxdocob.h>
    还要修改afxdocob.h 在其最后添加#ifdef _AFX_PACKING
    #pragma pack(pop)
    #endif
      

  5.   

    #ifdef _AFX_PACKING
    #pragma pack(pop)
    #endif搂住 上边折断是什么意思?pop是什么?〉
      

  6.   

    在~A()中加上delete this;,在程序中去掉delete pA;试试
      

  7.   

    有个问题问楼主,你是如何知道因为字节对齐的原因导致的崩溃呢?因为这种问题通常很难查,建议楼主分享一下经验给大家。(以下签名由MyCSDN回复工具生成)
    -----------------------------------------------
    MyCSDN 免费版 - CSDN离线数据浏览工具。
    http://community.csdn.net/Expert/TopicView1.asp?id=4608614
      

  8.   

    在MSDN上找到的。在MSDN中搜索错误提示中给出的信息。而巧的是这个错误,微软
    早就知道了。已经给出了解决办法。