4

This is a selection of my class

template <typename TValue, typename TPred = std::less<TValue> >
class BinarySearchTree {
public:
BinarySearchTree<TValue, TPred> &operator=(BinarySearchTree<TValue, TPred> const &tree) {
    if (this != &tree) {
        tree.VisitInOrder(Insert);
    }
    return *this;
}
bool Insert(TValue const &value) {
    return m_Insert(value, pRoot);
}
template <typename TVisitor> void VisitInOrder(TVisitor visitor) const;
...
};

and the following sequence wont work: VisitInOrder(Insert) because my compiler says that there are arguments missing

but my main looks like this and there i can use the function without its arguments:

void Print(int const x) { cout << x << endl; }

int main() {
    BinarySearchTree<int> obj1, obj2, obj3;
    obj1.Insert(10);
    obj1.VisitInOrder(Print);
    return 0;
}

full code here: http://pastebin.com/TJmAgwdu

0

1 Answer 1

3

Your function Insert is a member function, which means it accepts an implicit this pointer. You have to use std::bind() if you want to get a unary functor out of Insert():

if (this != &tree) {
    tree.VisitInOrder(
        std::bind(&BinarySearchTree::Insert, this, std::placeholders::_1));
}

Here is a live example showing the program compiling when the following assignment is present:

obj3 = obj1;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.