Re: Re: [cpp] 在一个函数内部动态创建一个类的对象,需要在此函数内释放它吗

DarkSpy coneos at 21cn.com
Thu Jun 15 08:54:13 CST 2006


xebec,您好! 
 
======== 13:37:51 您在来信中写道: ========
  

ge link,您好!

  你说的动态创建是指的是用&# 8220;new&# 8221;在堆上创建吧?如果是的话就需要自己显示使用&# 8220;delete&# 8221;释放内存。如果是在栈上创建的话,则不需要。

example:
    // need delete
    void foo(TypeA* tmp) {
        tmp = new TypeA();
        tmp->ooxx(); // do something...
        delete tmp; // need delete
    }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

如果抛开 "做为 example", 虽然没什么不可以这么做, 但仍然认为这是一个惊世骇俗的用法...

顺便庆祝一下我喜欢的球队都赢了
荷兰,西班牙,德国,墨西哥 和 意大利, 就是不喜欢巴西...

= = = = = = = = = = = = = = = = = = = = = = 
        致
礼!
              DarkSpy
                            coneos at 21cn.com
                 2006-06-15
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codingnow.com/pipermail/cpp/attachments/20060615/995a41b0/attachment.html


More information about the Cpp mailing list