Note that there are some explanatory texts on larger screens.

plurals
  1. POBuild Error:Undefined symbols for architecture x86_64:
    primarykey
    data
    text
    <p>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?</p> <p>This is the error:</p> <pre><code> Undefined symbols for architecture x86_64: "MyHashtable&lt;std::string, int&gt;::MyHashtable(int)", referenced from: _main in main.o "MyHashtable&lt;std::string, int&gt;::Insert(std::string, int)", referenced from: _main in main.o "MyHashtable&lt;std::string, int&gt;::GetKeys()", referenced from: _main in main.o "MyHashtable&lt;std::string, int&gt;::GetLength()", referenced from: _main in main.o "MyHashtable&lt;std::string, int&gt;::GetValue(std::string)", referenced from: _main in main.o "MyHashtable&lt;std::string, int&gt;::~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) </code></pre> <p>The cpp file of hashtable is as such:</p> <pre><code>#include &lt;iostream&gt; #include "Hashtable.h" #include &lt;string&gt; template&lt;typename T1,typename T2&gt; MyHashtable&lt;T1,T2&gt;::MyHashtable(int iSlots) { if(iSlots&lt;5) iSlots = 5; m_hashSlots = new HashElement&lt;T1,T2&gt;*[iSlots]; m_hashSlots = iSlots; m_Length = 0; } template&lt;typename T1,typename T2&gt; MyHashtable&lt;T1,T2&gt;::~MyHashtable() { if(m_hashSlots) { HashElement&lt;T1, T2&gt; * phead; for(int i = 0;i&lt;m_NumSlots;i++) { phead = m_hashSlots[i]; while(phead!=0) { HashElement&lt;T1, T2&gt;* pNext = phead-&gt;next; delete phead; phead = pNext; } } delete m_hashSlots; m_hashSlots = 0; } } template&lt;typename T1,typename T2&gt; int MyHashtable&lt;T1,T2&gt;::HashKey(T1 key) { char* keyString = (char*)key; int keyNum = 0; for(int i = 0;i&lt;strlen(keyString);i++) { int ascK = keyString[i]; keyNum += ascK; } return keyNum%m_NumSlots; } template&lt;typename T1,typename T2&gt; T1* MyHashtable&lt;T1,T2&gt;::GetKeys() { T1* keys = new T1[m_Length]; int index = 0; for(int i = 0;i&lt;m_NumSlots;i++) { HashElement&lt;T1,T2&gt; *phead = m_hashSlots[i]; while(phead!=0) { keys[index] = phead-&gt;key; index++; phead = phead-&gt;next; } } return keys; } template&lt;typename T1,typename T2&gt; T2 MyHashtable&lt;T1,T2&gt;::GetValue(T1 key) { int index = HashKey(key); HashElement&lt;T1,T2&gt; *phead = m_hashSlots[index]; while(phead) { if(phead-&gt;key==key) return phead-&gt;value; else phead = phead-&gt;next; } return NULL; } template&lt;typename T1,typename T2&gt; int MyHashtable&lt;T1,T2&gt;::GetLength() { return m_Length; } template&lt;typename T1,typename T2&gt; bool MyHashtable&lt;T1,T2&gt;::Insert(T1 key, T2 value) { int index = HashKey(key); HashElement&lt;T1,T2&gt; *phead = m_hashSlots[index]; while(phead) { if(phead-&gt;key == key) { int newValue = (int)(phead-&gt;value); newValue += int(value); return true; } else { phead = phead-&gt;next; } } HashElement&lt;T1,T2&gt;* newNode = new HashElement&lt;T1,T2&gt;(); newNode-&gt;key = key; newNode-&gt;value = value; phead-&gt;next = newNode; return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload