| |

VerySource

 Forgot password?
 Register
Search
View: 1177|Reply: 2

C++集合类Carray等是否会自动析构?

[Copy link]

1

Threads

1

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2022-8-30 13:00:01
| Show all posts |Read mode

#include <stdio.h>
#include <afxtempl.h>

struct Point
{
        double x;
        Point()
        {
                x=0;
        }
        ~Point()
        {
       
        }
};

void Set(Point* &pp)
{
        CArray<Point,Point> ary;
        Point p;

        p.x=1;
        ary.Add(p);
        pp=&ary[0];
        //这里系统自动释放了ary
}

void main()
{
        Point* pp;
        Set(pp);

        printf("pp:%i\r\n",(*pp).x);//这里没有pp的值
   //说明在Set函数中被析构了
       
}
Reply

Use magic Report

0

Threads

6

Posts

283.00

Credits

Full Member

Rank: 3Rank: 3

Credits
283.00

 China

Post time: 2022-10-21 21:17:44
| Show all posts
不会的,因为数值已经确定
Reply

Use magic Report

0

Threads

1

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2022-12-19 19:47:58
| Show all posts
不会的。。。。。。。。。。。。。。。
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list