Redian新闻
>
被分尸的富豪,原因是涉嫌乱伦
avatar
被分尸的富豪,原因是涉嫌乱伦# Love - 情爱幽幽
K*g
1
struct Node
{
int value;
std::vector children;
Node()
{
value = 0;
};
};
在一个函数里代码里,我先 Node* root= new Node;, 经过一系列处理后,然后
delete root;
请问这样会有问题吗?是不是在执行delete root;的时候,系统会自动的调用
children这个vector的deconstructor?请问有必要先把vector清空吗?
avatar
q*o
3
那个在加拿大河北籍的亿万富豪被杀害的事儿很多人都看到了吧?确实是有点让人难以
接受的,你说杀人就杀人,可是为什么会做的那么狠,为什么会把人家的尸体给剁成一
百份呢?这是有多大的仇呢?我现在就是钻到这个问题里面了,到底有多大的仇才会导
致对方把他杀害后并且把尸体剁成碎块儿呢?
最新报道出来了,这个犯罪嫌疑人承认了自己杀害了这个亿万富豪的事实,也说出了为
什么还杀害这个亿万富豪的原因。我想很多人应该都想不到,想不到这个富豪被杀的原
因原来那么扯,因为这个富豪想要娶这个凶手的女儿,而这个凶手表明这个富豪有很多
的女朋友,而且他的女朋友都会经常受到他的虐待,不忍心自己的女儿嫁给他所以就杀
了他。
越说越乱,现在还有人说这个被害者和嫌犯具有亲戚关系,死者是嫌犯的表姐夫,如果
这么说起来的话那这个富豪想要娶的姑娘就是他的表外甥女,突然感觉这个故事好复杂
,而且还涉嫌乱伦。如果这么说的话我就得说得过去了,乱伦是绝对不被允许的,而且
还身为长辈。
avatar
y*i
4
你这个vector里的指针怎么办?有其他地方有备份可以之后再delete还是就这样丢了?
如果就这样丢了的话那肯定有内存泄露
avatar
i*e
6
When the program executes the line:
delete root;
The Node's destructor will be called. Since you did not define a destructor,
the default destructor would not do anything for you. Of course, the vector
's destructor would be called automatically upon destruction of Node object.
(This is because vector is an object in C++). But this does not mean the
object's that's pointed by the vector of Nodes will be deleted.
You should implement your own destructor in the following way:
~Node() {
int sz = childs.size();
for (int i = 0; i < sz; i++) {
delete childs[i];
}
}
When you call delete root;
it will in turn calls delete childs[i] for each of its child. And each of
its child's child's destructor will also be called... and so on. Therefore,
all Nodes would be cleaned properly and there would no memory leaked.
一些常见面试题的答案与总结 -
http://www.ihas1337code.com
avatar
l*e
9
我的博客也不错哦
一个991,一个1450
娃哈哈
avatar
K*g
10
我问的是vector,至于vector里的指针,在delete root;之前就必须释放掉的。
这个问题挺简单的,但是今天我在写code的时候,纠缠了好一阵子。平时许多觉得理所
当然的问题,code的时候却发现挺绕的。

【在 y**i 的大作中提到】
: 你这个vector里的指针怎么办?有其他地方有备份可以之后再delete还是就这样丢了?
: 如果就这样丢了的话那肯定有内存泄露

avatar
c*k
11
在贬值啊
avatar
s*n
12
应该不会。

【在 K******g 的大作中提到】
: struct Node
: {
: int value;
: std::vector children;
: Node()
: {
: value = 0;
: };
: };
: 在一个函数里代码里,我先 Node* root= new Node;, 经过一系列处理后,然后

avatar
x*h
13
Adult Contents No
不实事求是啊
avatar
d*e
14
访问量半年中从50K平滑降到25K,很恐怖。
avatar
d*e
15

在哪里?瞻仰一哈。

【在 l*****e 的大作中提到】
: 我的博客也不错哦
: 一个991,一个1450
: 娃哈哈

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。