0

我的 main() 想打电话

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

程序.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'

这是旅行推销员应用程序。有人可以帮我解决这个错误吗?

4

1 回答 1

2

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

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

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

于 2013-10-09T00:20:15.830 回答