I am writing a program which implements a suffix trie in C++. I am trying to declare a recursive function with no parameters, but which needs to pass a pointer to itself.
I am defining it thus
public:
string longestRepeat(Node*);
in the header file, and
string Trie::longestRepeat(Node* start = &nodes[0]){
string deepest = "";
for(unsigned int i = 0; i < start->getEdges(); i++){
string child_deepest = longestRepeat(start->getChild(i));
if(child_deepest.length() > deepest.length())
deepest = child_deepest;
}
return deepest;
}
in the .cpp file, where node is a previously declared data structure.
However simply calling trie.longestRepeat()
in the main function results in the error "no matching function call for Trie::longestRepeat()
. Candidate expects 1 argument, 0 provided".