看板 EE_DSnP 關於我們 聯絡資訊
※ 引述《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
bumpwy:x 12/23 22:31