Почему я не могу вставить карту в вектор на новом элементе?

у меня есть vector из maps который я использую для хранения узла (векторный индекс), узла, на который он собирается (map-> second), и стоимости (map-> first). Он будет использоваться для построения графиков. Я не могу написать функцию, которая позволит мне вставить новый узел с тем узлом, на который он собирается, со стоимостью.

Пример:

vector[first_node].insert(make_pair(cost, second_node);

Используя вышеупомянутый метод, если есть существующий узел в местоположении [first_node] в векторе он будет добавлен к этой карте вместо создания совершенно новой точки. Я пытался использовать push_back, но это, похоже, не работает для меня.

Типичная ошибка:

error C2664: 'void std::vector<_Ty>::push_back(std::map<_Kty,double> &&)' : cannot convert parameter 1 from 'std::pair<_Ty1,_Ty2>' to 'std::map<_Kty,_Ty> &&'

for line: `edges.push_back(make_pair(second, cost));`

Соответствующий код для всей функции:

template <typename T>
void Graph<T>::map_edges(T first, T second, double cost) {
edges.resize(nodes.size()); //Resize the edges vector to make room for the new insertion. The new node already exists in a set of nodes called 'nodes'.
// Loop through the existing set of nodes...
for (set<T>::iterator node_it = nodes.begin();
node_it != nodes.end(); node_it++) {
//Check if the first node exists already.
if (first == *node_it) {
set<T>::iterator node_begin = nodes.begin();
set<T>::iterator node_pos = nodes.find(first);
int pos = distance(node_begin, node_pos);
//Then assign it's numerical value to the vector slot, and add the
//second and third words as a pair associated with that slot.
edges[pos].insert(make_pair(second, cost));
// edges.push_back(map<double, T>()); //This is where I would rather insert at a new location.
break;
}
}
}

Определение ребер:

vector<map<T, double> > edges;

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector