gpt4 book ai didi

c++ - 错误 : no matching function for call to const

转载 作者:行者123 更新时间:2023-11-28 03:07:51 25 4
gpt4 key购买 nike

我的 main() 想要调用

program p;   
p.isPath("c9", "c5")

program.h有

stack<City> isPath(City, City);

program.cpp有

stack<City> Program::isPath(City originCity, City destCity)
{
stack<City> flight; // = new Stack<City>();
originCity.setVisited(true);
flight.push(originCity);
checkPath(&originCity, &destCity, &flight);
return flight;
}

创建城市堆栈并将城市添加到堆栈中:

Program::Program()
{
City* c1 = new City("C1");
City* c2 = new City("C2");
City* c3 = new City("C3");
City* c4 = new City("C4");
City* c5 = new City("C5");
City* c6 = new City("C6");
City* c7 = new City("C7");
City* c8 = new City("C8");
City* c9 = new City("C9");
Program::found = true;

list<City>* allCities = new list<City>();
this->allCities->push_back(*c1);this->allCities->push_back(*c2); this->allCities->push_back(*c3);allCities->push_back(*c4); this->allCities->push_back(*c5);
this->allCities->push_back(*c6); this->City destCityallCities->push_back(*c7); this->allCities->push_back(*c8); this->allCities->push_back(*c9);

c1->addCityToCities(c7);
c1->addCityToCities(c2);
c2->addCityToCities(c3);
c3->addCityToCities(c4);
c4->addCityToCities(NULL);
c5->addCityToCities(c7);
c6->addCityToCities(c5);c7->addCityToCities(c6); c7->addCityToCities(c8);c8->addCityToCities(c2); c8->addCityToCities(c9);c9->addCityToCities(c6);

城市类有以下代码:

City::City()
{
list<City>* cities = new list<City>();
}
City::City(string _name){
this->name = _name;
list<City>* cities = new list<City>();
visited = false;

我有这个错误信息

main.cpp:  error: no matching function for call to 'Program::isPath(const char [3], const char [3])'
main.cpp: note: candidate is:
\include\Program.h: note: std::stack<City> Program::isPath(City, City)
\include\Program.h: note: no known conversion for argument 1 from 'const char [3]' to 'City'

这是旅行推销员应用程序。谁能帮我解决这个错误。

最佳答案

你的代码有很多问题,但是你问的是这个:

program p;   
p.isPath("c9", "c5")

假设“program”是“Program”,isPath 函数采用两个 City 参数,而不是两个字符串。您将需要传递 City 对象,或更改参数的类型。

关于c++ - 错误 : no matching function for call to const,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19260719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com