Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8021925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:07:29+00:00 2026-06-04T22:07:29+00:00

I have created a custom map for an assignment (It’s a generic templated map

  • 0

I have created a custom map for an assignment (It’s a generic templated map with it’s own custom iterator and a partial specialisation) but I’m getting undefined references to all of it’s functions when the application tries to use it in it’s code.

I have loooked at other questions on here with similar circumstances and I’m guessing I’ve got a mistake in my namespace or the location of the iterator or something that’s causing the application to not find it?

Here’s the relevant code:

        #ifndef MAP_H
#define MAP_H

#define SIZE 101

#include <string>

using std::string;

namespace myMap{


    ////////////////////START TEMPLATE//////////////////////

    template<class K, class V>
    class map
    {
        private:
            typedef struct SNode{
                K first;
                V second;
                SNode* next;
            } Node;

            Node** hashArray;
            Node* head;
            Node* tail;
            Node* lastEntry;

        public:
            map();
            ~map();

            V generateHash(K first);
            void addPair(K first, V second);
            void checkHeadTail();
            int count(K key);

            V& operator[](K first);

            class iterator
            {
                private:
                    Node* currentNode;
                    K first;
                    V second;
                public:
                    iterator();
                    iterator(Node* pos);
                    ~iterator();

                    void operator++(int);
                    Node* operator->();
                    bool operator!=(iterator other);
            };

            iterator begin(){iterator iter(head); return iter;}
            iterator end(){iterator iter(NULL); return iter;}
    };

    template<class K, class V>
    map<K, V>::map()
    {
        hashArray = new Node*[SIZE];
        for(unsigned int i = 0; i < SIZE; i++){
            hashArray[i] = NULL;
        }

        head = NULL;
        tail = NULL;
        lastEntry = NULL;
    }

    template<class K, class V>
    map<K, V>::~map()
    {
        for(unsigned int i = 0; i < SIZE; i++){
            if(hashArray[i] != NULL){
                Node* tmpNode = hashArray[i];
                Node* currentNode = hashArray[i];
                while(currentNode){
                    currentNode = currentNode->next;
                    delete tmpNode;
                    tmpNode = currentNode;
                }
            }
        }

        delete [] hashArray;
    }

    template<class K, class V>
    V map<K, V>::generateHash(K first)
    {
        V hash = 0;
        for(unsigned int j = 0; j < first.length(); j++){
            hash += first[j];
        }
        return hash % SIZE;
    }

    template<class K, class V>
    void map<K, V>::checkHeadTail()
    {
        if(hashArray[0] != NULL){
            head = hashArray[0];
            tail = hashArray[0];
        }

        Node* currentNode = *hashArray;
        while(currentNode->next){
            currentNode = currentNode->next;
        }
        tail = currentNode;
    }

    template<class K, class V>
    void map<K, V>::addPair(K first, V second)
    {
        Node* newEntry = new Node;
        newEntry->first = first;
        newEntry->second = second;
        newEntry->next = NULL;

        V hash = generateHash(first);

        if(hashArray[hash] == NULL){
            hashArray[hash] = newEntry;
            lastEntry = newEntry;
        } else {
            Node* currentNode = hashArray[hash];
            while(currentNode->next){
                if(currentNode->first == first){
                    currentNode->second += second;
                    lastEntry = currentNode;
                    return;
                }
                currentNode = currentNode->next;
            }
            if(currentNode->first == first){
                currentNode->second += second;
                lastEntry = currentNode;
                return;
            } else {
                currentNode->next = newEntry;
                lastEntry = newEntry;
                return;
            }
        }
        checkHeadTail();
    }

    template<class K, class V>
    V& map<K, V>::operator[](K first)
    {
        V second = 0;
        addPair(first, second);

        return lastEntry->second;
        checkHeadTail();
    }

    template<class K, class V>
    int map<K, V>::count(K key)
    {
        V hash = generateHash(key);
        if(hashArray[hash] != NULL){
            return true;
        }
        return false;
    }

    template<class K, class V>
    void map<K, V>::iterator::operator++(int)
    {
        currentNode = currentNode->next;
    }

    template<class K, class V>
    bool map<K, V>::iterator::operator!=(map::iterator other)
    {
        if(first == other->first) return false; return true;
    }

    template<class K, class V>
    typename map<K, V>::Node* map<K, V>::iterator::operator->()
    {
        return currentNode;
    }

    template<class K, class V>
    map<K, V>::iterator::iterator()
    {
        currentNode = NULL;
    }

    template<class K, class V>
    map<K, V>::iterator::iterator(Node* pos)
    {
        currentNode = pos;
    }

    ////////////////////SPECIALISATION///////////////////////////////

    template<class V>
    class map<string, V>
    {
        private:
            typedef struct SNode{
                string first;
                V second;
                SNode* next;
            } Node;

            Node** hashArray;
            Node* head;
            Node* tail;
            Node* lastEntry;

        public:
            map();
            ~map();

            V generateHash(string first);
            void addPair(string first, V second);
            void checkHeadTail();
            V count(string key);

            V& operator[](string first);

            class iterator
            {
                private:
                    Node* currentNode;
                    string first;
                    V second;
                public:
                    iterator();
                    iterator(Node* pos);
                    ~iterator();

                    void operator++(V);
                    Node* operator->();
                    bool operator!=(iterator other);
            };

            iterator begin();
            iterator end();
    };

    template<class V>
    map<string, V>::map()
    {
        hashArray = new Node*[SIZE];
        for(unsigned int i = 0; i < SIZE; i++){
            hashArray[i] = NULL;
        }

        head = NULL;
        tail = NULL;
        lastEntry = NULL;
    }

    template<class V>
    map<string, V>::~map()
    {
        for(unsigned int i = 0; i < SIZE; i++){
            if(hashArray[i] != NULL){
                Node* tmpNode = hashArray[i];
                Node* currentNode = hashArray[i];
                while(currentNode){
                    currentNode = currentNode->next;
                    delete tmpNode;
                    tmpNode = currentNode;
                }
            }
        }

        delete [] hashArray;
    }

    template<class V>
    V map<string, V>::generateHash(string first)
    {
        unsigned long hash = 0;
        for(unsigned int j = 0; j < first.length(); j++){
            hash += first[j];
        }
        return (V) hash % SIZE;
    }

    template<class V>
    void map<string, V>::checkHeadTail()
    {
        if(hashArray[0] != NULL){
            head = hashArray[0];
            tail = hashArray[0];
        }

        Node* currentNode = *hashArray;
        while(currentNode->next){
            currentNode = currentNode->next;
        }
        tail = currentNode;
    }

    template<class V>
    void map<string, V>::addPair(string first, V second)
    {
        Node* newEntry = new Node;
        newEntry->first = first;
        newEntry->second = second;
        newEntry->next = NULL;

        V hash = generateHash(first);

        if(hashArray[hash] == NULL){
            hashArray[hash] = newEntry;
            lastEntry = newEntry;
        } else {
            Node* currentNode = hashArray[hash];
            while(currentNode->next){
                if(currentNode->first == first){
                    currentNode->second += second;
                    lastEntry = currentNode;
                    return;
                }
                currentNode = currentNode->next;
            }
            if(currentNode->first == first){
                currentNode->second += second;
                lastEntry = currentNode;
                return;
            } else {
                currentNode->next = newEntry;
                lastEntry = newEntry;
                return;
            }
        }
        checkHeadTail();
    }

    template<class V>
    V& map<string, V>::operator[](string first)
    {
        V second = 0;
        addPair(first, second);

        return lastEntry->second;
        checkHeadTail();
    }

    template<class V>
    V map<string, V>::count(string key)
    {
        V hash = generateHash(key);
        if(hashArray[hash] != NULL){
            return true;
        }
        return false;
    }

    template<class V>
    map<string, V>::iterator::iterator()
    {
        currentNode = NULL;
    }

    template<class V>
    map<string, V>::iterator::iterator(Node* pos)
    {
        currentNode = pos;
    }

    template<class V>
    void map<string,V>::iterator::operator++(V)
    {
        currentNode = currentNode->next;
    }

    template<class V>
    typename map<string, V>::Node* map<string, V>::iterator::operator->()
    {
        return currentNode;
    }

    template<class V>
    bool map<string, V>::iterator::operator!=(map::iterator other)
    {
        if(first == other->first) return false; return true;
    }

} // END NAMESPACE

#endif // MAP_H

Errors:

undefined reference to `myMap::map<std::string, int>::begin()'
undefined reference to `myMap::map<std::string, int>::iterator::~iterator()'|
undefined reference to `myMap::map<std::string, int>::end()'|
undefined reference to `myMap::map<std::string, int>::iterator::~iterator()'|
undefined reference to `myMap::map<std::string, int>::iterator::~iterator()'|
undefined reference to `myMap::map<std::string, int>::iterator::~iterator()'|
undefined reference to `myMap::map<std::string, int>::iterator::~iterator()'|
undefined reference to `myMap::map<std::string, int>::iterator::~iterator()'|
undefined reference to `myMap::map<std::string, int>::begin()'|
undefined reference to `myMap::map<std::string, int>::iterator::~iterator()'|
undefined reference to `myMap::map<std::string, int>::end()'|
undefined reference to `myMap::map<std::string, int>::iterator::~iterator()'|
undefined reference to `myMap::map<std::string, int>::iterator::~iterator()'|
undefined reference to `myMap::map<std::string, int>::iterator::~iterator()'|
undefined reference to `myMap::map<std::string, int>::iterator::~iterator()'|
undefined reference to `myMap::map<std::string, int>::iterator::~iterator()'|

Erros occur when application tries to use the iterator as so:

map<string, int>::iterator iter;
for(iter = wordsCount.begin(); iter != wordsCount.end(); iter++){
    orderedList.addWord(iter->first, iter->second);
}

As part of the assignment, I am not allowed to change the use of the iterator above only the implementation, which I have had to create myself.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:07:30+00:00Added an answer on June 4, 2026 at 10:07 pm

    The implementation for the member functions which cause the error message are not in the header file for map<string, V>. I don’t see the implementations of map::begin(), map::end() and map::iterator::~iterator() anywhere. The most other functions seem to be implemented (didn’t check all), but those three are missing. map<K, V> implements begin() and end() inside the class, but the implementation of iterator::~iterator() is missing there, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add a ground overlay to a custom map and have created
I have created custom listview in that have list of textview & list of
I have created Custom Dialog for my application. While i run that application in
I have created custom posts and I want one page in my site to
I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in
I have created custom cell in which there are n number of image views.
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have created a custom JTree. That tree could be filtered to show only
I have created one custom list view item for my application. Suppose for any
I have created a custom CreateUser in Asp.Net Membership. Now what i want is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.