本文介绍了循环创建和销毁对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是C ++/stacko的新手,并且想主要从事以下工作:
I am new to C++/stacko and want to principally:
- 创建对象
- 为此读取大量数据
- 计算出对象的分数后,将其打印出来
- 从内存中删除对象,因为每个对象都有很多归因于它的变量
- 将其循环1000次
这看起来很简单,但是环顾四周后,我看到了有关析构函数的信息,但我不知道这就是我要找的东西.
It seems simple enough but after looking around I see things about destructors but I don't know if that's what I am looking for.
for(int i=0; i<1000; i++){
applicants object1;
object1.readin();
cout<<object1.calculate();
//How do I delete object1 and start again?
}
非常感谢您的帮助.我对这种语言一无所知.另外,我什至需要物品吗?我很困惑
Thank you so much for any help. I don't know hardly anything about this language. Also, do I even need objects? I'm confused
推荐答案
不必删除object1.
It is not necessary to delete object1.
对于循环的每次迭代,都会创建一个新对象object1(使用默认构造函数),并在"cout"语句之后对其进行销毁.
For every iteration of the loop, a new object object1 will be created (using default constructor) and destructed after the "cout" statement.
这篇关于循环创建和销毁对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!