tags:

views:

98

answers:

2
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;
    }
  }
}

I would like the user to enter in a StationTitle and for the program to locate the title and delete it if found. This is what I have come up with so far.
It is giving me a compile error: chief.cpp:145: error: no match for call to ‘(std::string) ()’

A: 

It seems like StationTitle is a property of the class in Transit, not a function. Can't be sure without more code.

Stargazer712
If that were the case, the error would be on line 143. Of course, maybe it is.... that makes more sense with the error :)
JoshD
Well...there's a good chance it would complain about line 143, but don't discount the possibility. Take line numbers with a grain of salt--the compiler is often wrong. Without even seeing a declaration of what is in the vector, it is nearly impossible to say.
Stargazer712
C++ does not have properties. Therefore, I am slightly confused here...
Billy ONeal
@Billy ONeal, public member variables. 99% of Properties that I have seen is nothing more than an excuse to use public variables, therefore I consider them to be virtually the same. Both expose the implementation of a class.
Stargazer712
@Stargazer712: If by "property" you are thinking of "C#-like properties," then no, public member variables are not like that at all. C# also has fields, which can be public and which are effectively the same thing as C++ data members.
James McNellis
@Stargazer: What @James said. A public member is a field, not a property.
Billy ONeal
@James and @Billy, I'm talking about how they are *used* in practice. I agree that they are different, and I agree that they are not inherently bad, but I see a lot of code in *practice* that uses them exactly as public member variables, and thus I generally refer to them in the same light.
Stargazer712
A: 

Your error is here:

 if(Transit->StationTitle() == ToDelete)

Change that line to this:

if(Transit->StationTitle == ToDelete)

OR

if(Transit->GetTitle() == ToDelete)
JoshD
Well it compiled when I made that adjustment, but the function does not delete the value as it should. That is neither of those suggestions worked.
chief
That's probably because the entered name doesn't match the title. Try adding some outputs or walking through with a debugger to see why.
JoshD
You are correct. However if the title has a space that seems to cause a problem. I cannot delete any title that includes a space.
chief
When you type it in, put quotes around it. If that doesn't work, you'll have to readline rather than a simple `cin >> stuff`
JoshD
Thanks for your help. getline(cin, ToDelete);
chief