作者bumpwy (bumpwy)
看板EE_DSnP
标题Re: [问题] homework8
时间Sun Dec 23 22:39:49 2007
※ 引述《ric2k1 (Ric)》之铭言:
※ 引述《bumpwy (bumpwy)》之铭言:
: 想在问一个问题
: 作业中要我们在 readgraph的memberfunction中allocate the memory for all the Vertex object,
: but wouldn't these objects be invalid out of the function's scope?
Local pointer variables may be invalidated. However, the "pointed memory"
will reside unless you "explicitly" delete it.
You can do something like:
_toVertices = new Vertex*[_numToVertices];
Vertex* tmpPtr[_numToVertices];
for (size_t i = 0; i < _numToVertices; i++)
tmpPtr = new Vertex;
_root = tmpPtr[0];
...
..
.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.121.133.136
1F:推 bumpwy:x 12/23 22:31
推文打错了...
请问tmpPtr的功用是?有点不懂..._toVertices 是用来存取所指到的vertex的地址对吧
?可是第二个指标就开始有点昏头了..(是要传一个pointer出去的用意吗?)
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.137.72.137
2F:推 ilway25:因为 _toV 不只指向一个,所以让他指到「存一群指标」的 12/23 22:48
3F:→ ilway25:位置... 12/23 22:49
4F:→ bumpwy:可是我不懂的是tmpPtr? 12/23 23:01