Apr 28, 2013 at 12:16am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
bool Trie::addDictionary (string filename){
fstream file("sae-sorted.dic" , ios::in);
string word;
if (!file.is_open())
{
cout << "File not found!\n" ;
return false ;
}
while (file >> word)
{
*this += word;
}
return true ;
}
error: no match for "operator+=" in "*(Trie*)this += word"
Someone please help!!
Last edited on Apr 28, 2013 at 12:16am UTC
Apr 28, 2013 at 12:38am UTC
You haven't defined operator+= (with a string rhs) for class Trie.
Apr 28, 2013 at 1:25am UTC
I'm not understanding your answer. So, how to fix this?
Apr 28, 2013 at 2:04am UTC
What do you expect to happen at line 12?
What is the declaration of the class Trie?
Apr 28, 2013 at 3:42am UTC
Well, I'm sorry but that didn't work. I'm trying to read words from a .txt letter by letter, using overload operator.
Apr 28, 2013 at 4:24am UTC
I'm not sure why you would want to overload the operator here anyway. Just add it to your string member. So, instead of this:
1 2 3 4
while (file >> word)
{
*this += word;
}
it would be something like this:
1 2 3 4
while (file >> word)
{
myString += word; //myString is a std::string object
}
The std::string library has an operator that will take this syntax.
Last edited on Apr 28, 2013 at 4:24am UTC
Apr 28, 2013 at 7:11pm UTC
This is the way I was instructed to do it, using this function and overload operator. I'm not trying to insert a word; I'm trying to read the words.
main.cpp:(.text._ZN4TrieC2Ev[_ZN4TrieC5Ev]+0x13): undefined reference to `vtable for Trie'
/tmp/ccQ979Q4.o: In function `Trie::~Trie()':
main.cpp:(.text._ZN4TrieD2Ev[_ZN4TrieD5Ev]+0x13): undefined reference to `vtable for Trie'
collect2: ld returned 1 exit status
What does this error even mean?
Last edited on Apr 28, 2013 at 7:13pm UTC