关于销毁对象问题!

lijdking 2003-04-11 07:45:34
在C++中销毁一个储存在栈中的对象是十分容易的。另一方面,要销毁动态创建的对象就困难多了。有很多解决办法,例如引用计数和智能指针,但是这样增加了复杂程度。C++程序员的第一印象是使用引用对象模型来解决问题实在是太糟了。

储存在栈中的对象与动态创建的对象有什么区别啊?他们是什么时候创建的,即他们是怎么创建的?

有很多解决办法,例如引用计数和智能指针,但是这样增加了复杂程度:这一句又是
说的什么意思?

使用引用对象模型来解决问题?

哪位大虾能不能给小弟指导指导?最好能举例子说明。谢谢!
...全文
136 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Chrisma 2003-04-11
  • 打赏
  • 举报
回复
看华中科技大学出版马光志编的《C++程序设计实践教程》,有例子。
bugfree 2003-04-11
  • 打赏
  • 举报
回复
>>引用计数和智能指针
They are the same technical in general.
It is a method to control not allocate momory for each obj. If you using the same obj, it will
add the reference number of it, if you delete obj, it will minus one, if the reference number
equal to 0, this obj will be removed.

For detail please look at the following:
====================
http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.22
bugfree 2003-04-11
  • 打赏
  • 举报
回复
The instance in stack will automaticly be deleted when program was ended.
But the instance using heap to allocate memory will not, you need to using
delete/delete[] to deallocate the ojb memory.
This is example:
1. From Stack: class A{}; A a; (a's memory from stack)
2. From Heap: calss A{}; A *a = new A; ...; delete a; (a's memory from heap)

lijdking 2003-04-11
  • 打赏
  • 举报
回复
还有什么叫内联函数?谢谢指导

69,364

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧