В программе, которую я пишу, у меня есть вектор указателей, чтобы попытаться сохранить использование памяти, и хотя это сделает мою программу более эффективной, я испытываю трудности с передачей вектора указателей в функция direct(). Любая помощь с правильным синтаксисом для передачи этого в функцию с благодарностьюC++: передача вектора указателей в функцию
Отображается текущая ошибка: «ошибка не может преобразовать» std :: vector *>'to' const string '... для аргумента «1» ... линии эта ошибка быть помечена на это линия, в которой Направляйте называются функция
#include <iostream>
#include <vector>
using namespace std;
// a function used to display an array used for testing purposes
void display_array(const string *arr, size_t size)
{
int i;
for (i = 0; i < size; i++){
cout<<(int(arr[i][0]))-64;
cout<<(int(arr[i][1]))-64;
cout<<",";
}
}
// Takes in the connections to the start and the connections to the end and returns the connection if
//there is a direct connection else returns 0
string direct(const string *destination, char *start, size_t destination_size) {
for (int i = 0; i<destination_size;i++)
if ((&destination[i][0] == start) or (&destination[i][1] == start))
return destination[i];
}
int main()
{
string current;
std::vector<string> paths;
std::vector<string*> start_connections;
std::vector<string*> destination_connections;
char start;
char destination;
cout<<"Input paths in the form 'AB'(0 to exit)\n";
cin>>current;
while (current != "0"){
paths.push_back(current);
cin>>current;
}
cout<<"Input starting location\n";
cin>> start;
cout<<"Input final destination\n";
cin>>destination;
for(int i = 0; i < paths.size(); i++) {
if ((paths[i][0] == destination) or (paths[i][1] == destination)) //all connections to the destination
destination_connections.push_back(&paths[i]); // paths stored as a pointer to paths array
if ((paths[i][0] == start) or (paths [i][1] == start)) //all connections to the start
start_connections.push_back(&paths[i]); // paths stored as a pointer to paths array
}
cout<<direct(&destination_connections,&start,destination_connections.size());
if(!paths.empty())
display_array(&paths[0], paths.size());
}
'direct' берет' string * 'как свой первый аргумент, но вы пытаетесь передать ему' vector * '. Что вы ожидаете от этого? –
jwodder