Question: When debugging my program, I keep getting Error C3867 on line 226. The Description for this error says 'StringSet::size': non-standard syntax; use '&' to create

When debugging my program, I keep getting Error C3867 on line 226.

The Description for this error says

'StringSet::size': non-standard syntax; use '&' to create a pointer to member.

Where do I use '&' to fix my program?

#include #include #include #include #include #include #include using namespace std;

//StringSet Class class StringSet { public: StringSet(); StringSet(const string initialStrings[], int arraysize); bool add(const string s); bool remove(const string s); void clear(); int size(); void output(); friend StringSet operator *(const StringSet &set1, const StringSet &set2); friend StringSet operator +(const StringSet &set1, const StringSet &set2);

private: int search(const string s); vector data; };

//default construct StringSet::StringSet() {

}

//initializing string set constructor StringSet::StringSet(const string initialStrings[], int arraysize) { int i; for (i = 0; i < arraysize; i++) { data.push_back(initialStrings[i]);

} }

//this method simply outputs all strings to the console. void StringSet::output() { int i; for (i = 0; i < data.size(); i++) { cout << " " << data[i] << endl;

} }

//erase all entries in the stringset void StringSet::clear() { data.clear();

}

//# of entriest in stringset int StringSet::size() { return data.size(); }

//private mem function searchers vector for the target string. when found // the index is returned otherwise -1 is returned

int StringSet::search(const string s) { int i; for (i = 0; i < data.size(); i++) { if (data[i] == s) return i; } return -1; }

// add a new entry to vector bool StringSet::add(const string s) { int i; i = search(s); if (i >= 0) { return false; } data.push_back(s); return true; }

//remove a entry from the vector

bool StringSet::remove(const string s) { int i; i = search(s); if (i >= 0) { vector temp; for (int j = 0; j < data.size(); j++) { if (data[j] != s) { temp.push_back(data[j]);

}

}

data.clear();

for (int j = 0; j < temp.size(); j++) { data.push_back(temp[j]); } return true; } return false; }

//intersect the current stringset with the otherset StringSet operator *(const StringSet &set1, const StringSet &set2) { StringSet temp; int i, j; for (i = 0; i < set1.data.size(); i++) { for (j = 0; j < set2.data.size(); j++) { if (set1.data[i] == set2.data[j]) { temp.add(set1.data[i]); } } } return temp; }

//union the current stringset and otherset and return it

StringSet operator +(const StringSet &set1, const StringSet &set2) { StringSet temp; int i; for (i = 0; i < set1.data.size(); i++) { temp.add(set1.data[i]);

}

for (i = 0; i < set2.data.size(); i++) { temp.add(set2.data[i]); } return temp; }

//function prototype

void readFileKeywords(StringSet &setDocument, const char filename[]); void inputKeywords(StringSet &setKeywords); void inputKeywords(StringSet &setKeywords) { string s; cout << "Enter keywords, 1 for each line. Enter a blank line when finished." << endl; do { getline(cin, s); if (s != string("")) {

setKeywords.add(s); } } while (s != string("")); }

//ReadFileKeywords: //opens the specified files for reading and inputs its words //into the StringSet void readFileKeywords(StringSet &setDocument, const char filename[]) { ifstream in_stream; string s; //open the file in_stream.open(filename); if (in_stream.fail()) { cout << "Input file opening failed." << endl; exit(-1); }

//read each word from file til end while (!in_stream.eof()) { in_stream >> s; setDocument.add(s); } in_stream.close(); }

int main() { //variable declaration StringSet doc1; StringSet doc2; StringSet query; readFileKeywords(doc1, "doc1.txt"); readFileKeywords(doc1, "doc2.txt"); cout << "Enter set of keywords for the query." << endl; inputKeywords(query); // calculate intersection StringSet intersect1 = doc1 * query; StringSet intersect2 = doc2 * query; // calculate similiarity double sim1 = intersect1.size() / (sqrt(doc1.size()) *sqrt(query.size)); cout << "The similiarity to document 1 is " << sim1 << endl; double sim2 = intersect2.size() / (sqrt(doc2.size()) *sqrt(query.size)); cout << "The similiarity to document 2 is" << sim2 << endl; system("pause"); return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!