さて、私は自分自身に、パラメータでベクトルを直接渡す方法があるかどうか疑問に思っています。つまり、次のようになります。
int xPOS = 5, yPOS = 6, zPOS = 2;
//^this is actually a struct but
//I simplified the code to this
std::vector <std::vector<int>> NodePoints;
NodePoints.push_back(
std::vector<int> {xPOS,yPOS,zPOS}
);
もちろん、このコードはエラーになります。タイプ名は許可されておらず、「)」が必要です
構造体を使用したはずですが、次のArray[index][index]
ようにノードの位置にアクセスする必要がある抽象仮想マシンにデータを渡す必要があります。
public GPS_WhenRouteIsCalculated(...)
{
for(new i = 0; i < amount_of_nodes; ++i)
{
printf("Point(%d)=NodeID(%d), Position(X;Y;Z):{%f;%f;%f}",i,node_id_array[i],NodePosition[i][0],NodePosition[i][1],NodePosition[i][2]);
}
return 1;
}
もちろん、私はこのようにそれを行うことができます:
std::vector <std::vector<int>> NodePoints;//global
std::vector<int> x;//local
x.push_back(xPOS);
x.push_back(yPOS);
x.push_back(zPOS);
NodePoints.push_back(x);
またはこれ:
std::vector <std::vector<int>> NodePoints;//global
std::vector<int> x;//global
x.push_back(xPOS);
x.push_back(yPOS);
x.push_back(zPOS);
NodePoints.push_back(x);
x.clear()
しかし、私は2つのうちどちらがより速い/より効率的/より良いのだろうかと思っていますか?または、最初のコードを機能させる方法はありますか(最初のスニペット)?