basic_string& assign() function is called in my own container before Insert() function

  assign, c++, insert, multimap, templates

I am trying to implement template multimap Binary Tree container in C++.
The elements in this container are Node class pointers, which have pointer to the right element (if the key value is more than previous element’s key), to the left element (if the key value is less than previous element’s key) and extra (if the key value is equal to the previous element’s key). The main Node pointer is root which is the beginning of the binary tree.

template <typename KeyType, typename InfoType>
class BinaryTree
{
public:
    BinaryTree();
    void Insert(KeyType key, InfoType data);

private:
    class Node
    {
    public:
        Node(KeyType key = KeyType(), InfoType data = InfoType(), Node* previous = nullptr, Node* left = nullptr, Node* right = nullptr, Node* extra = nullptr)
        {
            this->data = data;
            this->key = key;
            this->previous = previous;
            this->left = left;
            this->right = right;
            this->extra = extra;
        }

        Node* left;
        Node* right;
        Node* extra;
        Node* previous;
        InfoType data;
        KeyType key;
    };

    Node* root;
};

Also, I have implemented BinaryTree constructor and Insert() function for this container

template <typename KeyType, typename InfoType>
BinaryTree<typename KeyType, typename InfoType>::BinaryTree()
{
    root = nullptr;
}

template <typename KeyType, typename InfoType>
void BinaryTree<typename KeyType, typename InfoType>::Insert(KeyType key, InfoType data)
{
    if (root == nullptr)
        root = new Node(key, data);
    else
    {
        Node* temp = root;

        while ((key >= temp->key && temp->right != nullptr) || (key <= temp->key && temp->left != nullptr))
        {
            if (key < temp->key)
            {
                temp = temp->left;
            }
            else if (key > temp->key)
            {
                temp = temp->right;
            }
        }

        if (key > temp->key)
        {
            temp->right = new Node(key, data, temp);
        }
        else if (key < temp->key)
        {
            temp->left = new Node(key, data, temp);
        }
        else if (key == temp->key)
        {
            Node* beginning = temp;

            while (temp->extra != nullptr)
            {
                temp = temp->extra;
            }

            temp->extra = new Node(key, data, beginning);

            return;
        }
    }
}

And the main function is like this

int main()
{
    BinaryTree<int, std::string> bt;
    bt.Insert(6, "apple");
    bt.Insert(8, "carrot");
    bt.Insert(10, "parrot");
    bt.Insert(4, "banana");
    bt.Insert(1, "poncho");
    bt.Insert(7, "zero");
    bt.Insert(10, "money");
    bt.Insert(8, "food");
    bt.Insert(2, "delivery");

    return 0;
}

My problem is that while debugging I try to step into the insert function, but instead of that the program firstly calls function called:

basic_string& assign(_In_reads_(_Count) const _Elem* const _Ptr, _CRT_GUARDOVERFLOW const size_type _Count)

Why does it happen? And is it gonna slow down my program? Because one of my main objectives was to make the container’s Insert function faster using binary tree implementation. There is nothing wrong with compiler itself, I don’t get any errors or warnings. I just have no idea why this function is called before my Insert() function. Also, I wanted to mention that all of this code is in the same file, and the class is not divided into header and .cpp file (but actually even in this scenario I get the same problem).

Source: Windows Questions C++

LEAVE A COMMENT