A function has 2
arguments. One type is a vector of class(has a string private variable). The other is the string it looks for. I tried ==
both string but it won't work. I expected it but was hoping I could use a friend
on it but it appears to work only for 2
classes.
I tried searching up using a friend
function on class Term
, but couldn't find results that used one class and one function. Besides friend
, I can't think of another way.
class Term
{
string str;
unsigned long long int weight;
Term(string s, long int w) : str(s), weight(w) {}
};
//my teacher provided this code so I can't change anything above
int FindFirstMatch(vector<Term> & records, string prefix)
//prefix is the word it looks for and returns the earliest time it appears.
{
for (int i=0; i<records.size(); i++)
{
if (records[i].str==prefix)
{
//I just need to get this part working
return i;
}
}
}`
It says str
is a private member of Term
. Which is why I was hoping to simply use a friend
on it.