bool find_solutions(const string if_need_all, vector< vector<char> > table, vector<int> ships, int row[], int col[]){
sort(ships.begin(), ships.end(), greater<int>());//sort the ship length in descending order
static int counter = 0; //counter that tracks if the ship is to be placed vertically or horizontally
static int s = 0; //index of ship using
int fill;//ship to fill
int filling;//keep track how much the ship has been filled
if(s == ships.size()) return true;
for(unsigned int i = 0; i<table.size(); ++i){
filling = 0;
fill = ships[s];
for(unsigned int j = 0; j<table[i].size(); ++j){
if(counter == 0 && insertable(table,row,col,i,j,counter,fill)){
while(filling<fill){
table[i][j+filling] = fill;
col[j+filling]--;
filling++;
}
row[i] -= fill; s++;
find_solutions(if_need_all, table, ships, row,col);
}
else{
counter++;
}
if(counter == 1 && insertable(table,row,col,i,j,counter,fill)){
while(filling<fill){
table[i+filling][j] = fill;
row[i+filling]--;
filling++;
}
col[j] -= fill; s++;
find_solutions(if_need_all, table, ships, row, col);
}
else{
counter--;
}
}
}
if(s != ships.size()) return false;
else return true;
}
main.cpp: In function ‘bool find_solutions(std::__cxx11::string, std::vector<std::vector<char> >, std::vector<int>, int*, int*)’:
main.cpp:277:67: error: call of overloaded ‘insertable(std::vector<std::vector<char> >&, int*&, int*&, unsigned int&, unsigned int&, int&, int&)’ is ambiguous
if(counter == 0 && insertable(table,row,col,i,j,counter,fill)){
^
main.cpp:13:6: note: candidate: bool insertable(const std::vector<std::vector<char> >&, const int*, const int*, int, int, int, int)
bool insertable(const vector< vector<char> >& inboard, const int r[], const int c[],
^
main.cpp:125:6: note: candidate: bool insertable(std::vector<std::vector<char> >, const int*, const int*, int, int, int, int)
bool insertable(const vector< vector<char> > inboard,const int r[], const int c[],co
^
kann mir jemand sagen, welchen Fehler ich gemacht habe? Ich suchte online, dass Websites sagt, es ist entweder Variable erstellt mehrere Male oder Funktionsname bereits in der STL-Bibliothek vorhanden. Ich habe beide Bedingungen überprüft und sie gelten nicht für mein Problem. Ist es das Füllen, das Problem oder andere Variable verursacht, oder ist es die Funktion?Fehler: Anruf von überlastet ist mehrdeutig
wo ist dein „einsetzbar“ -Funktion? –
Nicht annähernd genug Informationen hier, um eine sinnvolle Antwort zu geben, aber es sieht so aus, als ob du 'namespace std' verwendest. Es gibt viel Platz für Gemeinheiten wie eine Funktion, die Sie definieren, um einen Ausschuss mit einer gleichnamigen Funktion in der Standardbibliothek zu erhalten. – user4581301