答复: [cpp] 初次光临,请多指教

Yiqing He yiqing.he at mediazone.com.cn
Mon Jul 10 15:53:18 CST 2006


应该这样写

xWrapper(){xItem = new X; }




 

________________________________

发件人: cpp-bounces at codingnow.com [mailto:cpp-bounces at codingnow.com] 代表 ling
发送时间: 2006年7月10日 10:19
收件人: C++ Discuss Group
主题: [cpp] 初次光临,请多指教

 

今天看了c++对话系列,为什么说下面的类程序会因为内存问题而崩溃呢?

 

#include "xStruct.h" // definition of struct X

class xWrapper
{
    X* xItem;
public:
    xWrapper() : xItem(new X) { }
    ~xWrapper() { delete xItem; }

    void dump() { /* dumps xItem to cout */ }
};

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codingnow.com/pipermail/cpp/attachments/20060710/e2e70b7a/attachment-0001.html


More information about the Cpp mailing list