Context
Grade a course for data structures and algorithms, exercise in using the AVL tree and hash tables to analyze input to create a dictionary file, and then use this file to perform spellchecking.
NB: I do not ask for help in solving this problem, which is not something that is difficult for me. I ask for help to understand the aspects of passing / using an object to a C ++ function, which causes me considerable disappointment. This aspect of C ++ is not part of the evaluation, there are no bindings to it, I just have a personal problem sending the code, I don't like the design.
Problem
Passing a functor to a recursive function results in a compiler error, "attempt to use a remote function." I thought this was a problem with passing a functor by value, so I changed the parameter for passing by reference, which gives "an inappropriate member function to call the <public member function from the AVL tree that starts the recursion>," in this case I don’t I know how to change a function declaration to fit. I also tried to make the parameter: const UnaryFunction& action(permalink to object-object), but this gives a compiler error " no matching function for call to object of type 'const std::__1::__mem_fn<void (DictGen::*)(std::__1::basic_string<char> &)>'", in which case I can not understand why it will not match DictGen :: output signature.
the code
Relevant parts of tree tree AVL:
template <class T>
struct AVLNode
{
AVLNode<T>* lChild;
AVLNode<T>* rChild;
AVLBalance balFac;
T data;
};
template <class T>
class AVLTree<T>
{
...
AVLNode<T>* root;
template <class UnaryFunction>
void inorderAction( AVLNode<T>* node, UnaryFunction action )
{
if ( node != NULL )
{
inorderAction( node->lChild, action );
action( node->data );
inorderAction( node->rChild, action );
}
}
public:
template <class UnaryFunction>
void inorder( UnaryFunction action )
{
inorderAction( root, action );
}
}
Relevant parts of the DictGen class:
class DictGen
{
...
FILE* outStream;
AVLTree<std::string> dict;
void output( std::string& word )
{
fprintf( outstream, "%s\n", word.c_str() );
}
public:
goGoGadgetDictionaryGenerator()
{
...
dict.inorder( std::mem_fn( &DictGen::output ) );
}
}
Interpretation / Translation
AVL , node, UnaryFunction action. DictGen FILE *, DictGen , -- dict.inorder( ... ).
/
, , , C . , ; DictGen.
- ++-, , .
, SO ( -), Google PDF- . , , . , a const UnaryFunction& , , .
, outStream.
, , SO, , ++ , . SO, , .
- ?
- / , ?
?
, , , ?
SO, , , . , , .