class Catalog
{
// string StationTitle;
string StationLocation;
public:
string StationTitle;
Catalog()
{
StationTitle = "";
StationLocation = "";
}
Catalog(string Title, string Location)
{
StationTitle = Title;
StationLocation = Location
}
void SetTitle(string Title) { StationTitle = Title; }
void SetLocation(string Location) { StationLocation = Location; }
string GetTitle() { return StationTitle; }
string GetLocation() { return StationLocation; }
};
class StationList
{
vector<Catalog> List; //create the vector
vector<Catalog>::iterator Transit;
public:
void Fill();
void Remove();
void Show();
};
void StationList::Remove()
{
string ToDelete;
cout << "Enter title to delete: " << endl;
cin >> ToDelete;
for(Transit = List.begin() ; Transit !=List.end() ; Transit++)
{
if(Transit->StationTitle() == ToDelete)
{
List.erase(Transit); //line 145
return;
}
}
}
我希望用户输入StationTitle并让程序找到标题并删除它(如果找到)。这是我到目前为止所提出的 它给了我一个编译错误:chief.cpp:145:错误:不匹配调用'(std :: string)()'
答案 0 :(得分:0)
似乎StationTitle是Transit中类的属性,而不是函数。没有更多代码就无法确定。
答案 1 :(得分:0)
您的错误在这里:
if(Transit->StationTitle() == ToDelete)
将该行更改为:
if(Transit->StationTitle == ToDelete)
OR
if(Transit->GetTitle() == ToDelete)