template<typename Elem>
struct Node {
    Elem Key;
    Node <Elem>* parent = nullptr;
    Node <Elem>* left = nullptr;
    Node <Elem>* right = nullptr;

    Node(Elem k);

template<typename Elem>
Node<Elem>::Node(Elem k):Key{k}{}

template<typename Elem>
class BinaryTree{
    class iterator; //Node<Elem>*
    iterator root;
    void insert(Elem val);
    void remove(iterator& z);


template<typename Elem>
class BinaryTree<Elem>::iterator{
    iterator(Node<Elem>* p);
    Node<Elem>* curr = nullptr;

    iterator& parent(); //set curr = curr->right
    iterator& left();
    iterator& right();

    void setparent(iterator& b);//sets this.curr->parent = b.curr->parent
    void setleft(iterator& b);
    void setright(iterator& b);

    iterator& Parent(); //Creates a new iterator that points to curr->parent and returns a reference to that
    iterator& Left();
    iterator& Right();

    Elem& operator *(); // returns curr->Key
    bool operator ==(iterator& b);
    bool operator !=(iterator& b);
    void operator =(iterator& b);


I made a minimum function to be used in the BinaryTree<Elem>::remove(iterator& z) function, implemented as:

template<typename Elem>
typename BinaryTree<Elem>::iterator & minimum(typename BinaryTree<Elem>::iterator & z) {
    while(z.Left().curr != nullptr) {
    return z;

The remove function, when it calls minimum() with z.Right() as an argument, gives the error C2783, which states that:

“ BinaryTree :: iterator&minimum(BinaryTree :: iterator&)':无法推断'Elem'的模板参数”


template<typename Elem>
void BinaryTree<Elem>::remove(iterator& z) {
    if (z.Left().curr == nullptr) {
        transplant(*this, z, z.Right());//The z.Right() creates a new iterator on the heap, whose curr pointer points to z.curr->right

    else if (z.Right().curr != nullptr) {
        transplant(*this, z, z.Left());

    else {

        iterator y = minimum(z.Right()); //-> This gives the error C2783 and C2762 (no matching overloaded function found)
        if (y.Parent() != z) {
            transplant(*this, y, z.Right());
            y.curr->right = z.curr->right;
            y.Right().curr->parent = y.curr;
        transplant(*this, z, y);
        y.curr->left = z.curr->left;
        y.curr->left->parent = y.curr;