作者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