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 6652207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:06:28+00:00 2026-05-26T01:06:28+00:00

I am completely new in programming with c++ using the Xcode IDE. What I

  • 0

I am completely new in programming with c++ using the Xcode IDE. What I do is I created a Hashtable myself, and clicked the build button, and I got compilation errors as such. Does anyone have ideas about what is going wrong?

This is the error:

    Undefined symbols for architecture x86_64:
  "MyHashtable<std::string, int>::MyHashtable(int)", referenced from:
      _main in main.o
  "MyHashtable<std::string, int>::Insert(std::string, int)", referenced from:
      _main in main.o
  "MyHashtable<std::string, int>::GetKeys()", referenced from:
      _main in main.o
  "MyHashtable<std::string, int>::GetLength()", referenced from:
      _main in main.o
  "MyHashtable<std::string, int>::GetValue(std::string)", referenced from:
      _main in main.o
  "MyHashtable<std::string, int>::~MyHashtable()", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The cpp file of hashtable is as such:

#include <iostream>
#include "Hashtable.h"
#include <string>

template<typename T1,typename T2>
MyHashtable<T1,T2>::MyHashtable(int iSlots) 
{
    if(iSlots<5) iSlots = 5;
    m_hashSlots = new HashElement<T1,T2>*[iSlots];
    m_hashSlots = iSlots;
    m_Length = 0;
}

template<typename T1,typename T2>
MyHashtable<T1,T2>::~MyHashtable()
{
    if(m_hashSlots)
    {
        HashElement<T1, T2> * phead;
        for(int i = 0;i<m_NumSlots;i++)
        {
            phead = m_hashSlots[i];
            while(phead!=0)
            {
                HashElement<T1, T2>* pNext = phead->next;
                delete phead;
                phead = pNext;
            }
        }
        delete m_hashSlots;
        m_hashSlots = 0;
    }
}

template<typename T1,typename T2>
int MyHashtable<T1,T2>::HashKey(T1 key)
{
    char* keyString = (char*)key;
    int keyNum = 0;
    for(int i = 0;i<strlen(keyString);i++)
    {
        int ascK = keyString[i];
        keyNum += ascK;
    }
    return keyNum%m_NumSlots;
}

template<typename T1,typename T2>
T1* MyHashtable<T1,T2>::GetKeys()
{
    T1* keys = new T1[m_Length];
    int index = 0;
    for(int i = 0;i<m_NumSlots;i++)
    {
        HashElement<T1,T2> *phead = m_hashSlots[i];
        while(phead!=0)
        {
            keys[index] = phead->key;
            index++;
            phead = phead->next;
        }
    }
    return keys;
}

template<typename T1,typename T2>
T2 MyHashtable<T1,T2>::GetValue(T1 key)
{
    int index = HashKey(key);
    HashElement<T1,T2> *phead = m_hashSlots[index];
    while(phead)
    {
        if(phead->key==key)
            return phead->value;
        else
            phead = phead->next;
    }
    return NULL;
}


template<typename T1,typename T2>
int MyHashtable<T1,T2>::GetLength()
{
    return m_Length;
}

template<typename T1,typename T2>
bool MyHashtable<T1,T2>::Insert(T1 key, T2 value)
{
    int index = HashKey(key);
    HashElement<T1,T2> *phead = m_hashSlots[index];
    while(phead)
    {
        if(phead->key == key) {
            int newValue = (int)(phead->value);
            newValue += int(value);
            return true;
        } else {
            phead = phead->next;
        }
    }
    HashElement<T1,T2>* newNode = new HashElement<T1,T2>();
    newNode->key = key;
    newNode->value = value;
    phead->next = newNode;
    return true;
}
  • 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-05-26T01:06:29+00:00Added an answer on May 26, 2026 at 1:06 am

    Template definition inside of cpp file? Try putting it inside of the header file. The compiler will create a new instance of the class when you declare the instance (MyHashTable<int,int> myVar;), and so during include the entire class definition needs to be present. Hence, the h file instead of the cpp file.

    I’m not sure if this is the entire problem, as I don’t use XCode, but it sounds like the issue to me.

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

Sidebar

Related Questions

I'm completely new to programming and I'm trying to build an autorespoder to send
I am completely new to ASP.NET programming, and was asked to work on a
I am an inexperienced programmer , completely new to programming for windows . I
I'm super new to programming and I've been using appengine to help me learn
I'm new to audio programming so excuse me if I'm not using the right
I am a programming enthusiast with a basic programming background, but I'm completely new
I'm completely new to programming on the Android platform but I'm interested in learning
I'm totally, completely new to programming, so please forgive what is probably a stupid
Completely new to asp.net mvc... completely new to web apps so bear with me...
I am completely new to ruby and I inherited a ruby system for a

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.