我有這樣的構造Foreach循環使用指針
class Vertex
{
Vertex();
~Vertex();
Edge* adjacencies;
};
我想那裏是陣列鄰接的,但它不能建立。所以我創建了指針(Edge也是我創建的類)。
而我有這段代碼與foreach循環,必須迭代所有鄰接關係,但是,當然,它不編譯。
Vertex getted_vertex = vertexQueve.top();
for(Edge & e: getted_vertex.adjacencies)
{
Vertex v = Vertex(e._idFrom);
}
我應該改變構造函數還是循環?
使用'vector'。 –
使用'std :: vector',你可以擁有你想要的數組。 – StoryTeller