作者ric2k1 (Ric)
看板EE_DSnP
标题Re: [问题] homework8
时间Sun Dec 23 22:06:04 2007
※ 引述《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