std::array<LINE,10> currentPaths=PossibleStrtPaths();
LINE s=shortestLine(currentPaths); //ERROR
LINE CShortestPathFinderView::shortestLine(std::array<LINE,10> *currentPaths)
{
std::array<LINE,10>::iterator iter;
LINE s=*(currentPaths+1); //ERROR
for(iter=currentPaths->begin()+1;iter<=currentPaths->end();iter++)
{
if(s.cost>iter->cost)
s=*iter;
}
std::remove(currentPaths->begin(),currentPaths->end(),s);
//now s contains the shortest partial path
return s;
}
在這兩個語句我得到了同樣的錯誤:no suitable conversion from std::array<LINE,10U>*currentPaths to LINE
。這是爲什麼?我應該以另一種方式通過陣列嗎?我也嘗試通過currentPaths作爲參考,但它告訴我該類型的引用無法初始化。我應該如何將這個std :: array <>傳遞給函數?
'*(currentPaths + 1);'你能做到嗎?或者你的意思是'(* currentPaths)[1]' – andre
@ahenderson我想將_currentPaths_的第二個LINE對象賦給_s_。是不是'*(currentPaths + 1)'與'currentPaths [1]'相同? – Ghost
除非'null'是通過引用傳遞的可能值,否則最好走。使用你的方法,你可能正在訪問'(currentPaths)[10]',這與currentPaths [1]'相同。記住你有一個指向數組而不是數組的指針。 – andre