Undefined reference to...
Mar 26, 2014 at 8:08pm UTC
When I try to compile this program in linux I get the error 'Undefined reference to' and then it gives me three functions all in the nodes_LLoLL file. I am not very experienced with linux and have tried to find solutions to this on Google but nothing seems to work. I am thinking somehow the nodes_LLoLL.h file is not being included when I compile? Any help would be much appreciated and thanks in advance guys!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
//nodesLLoLL.h
#ifndef NODES_LLOLL_H
#define NODES_LLOLL_H
#include <iostream> // for ostream
namespace cs3358Spring2014Assign06P1
{
// child node
struct CNode
{
int data;
CNode* link;
};
// parent node
struct PNode
{
CNode* data;
PNode* link;
};
// toolkit functions for LLoLL based on above node definitions
void Destroy_cList(CNode*& cListHead);
void Destroy_pList(PNode*& pListHead);
void ShowAll_DF(PNode* pListHead, std::ostream& outs);
void ShowAll_BF(PNode* pListHead, std::ostream& outs);
}
#endif
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
//nodes_LLoLL.cpp
#include "nodes_LLoLL.h"
#include "cnPtrQueue.h"
#include <iostream>
using namespace std;
namespace cs3358Spring2014Assign06P1
{
void Destroy_cList(CNode*& cListHead)
{
int count = 0;
CNode* cNodePtr = cListHead;
while (cListHead != 0)
{
cListHead = cListHead->link;
delete cNodePtr;
cNodePtr = cListHead;
++count;
}
cout << "Dynamic memory for " << count << " CNodes freed"
<< endl;
}
void Destroy_pList(PNode*& pListHead)
{
int count = 0;
PNode* pNodePtr = pListHead;
while (pListHead != 0)
{
pListHead = pListHead->link;
Destroy_cList(pNodePtr->data);
delete pNodePtr;
pNodePtr = pListHead;
++count;
}
cout << "Dynamic memory for " << count << " PNodes freed"
<< endl;
}
// do depth-first traversal and print data
void ShowAll_DF(PNode* pListHead, ostream& outs)
{
while (pListHead != 0)
{
CNode* cListHead = pListHead->data;
while (cListHead != 0)
{
outs << cListHead->data << " " ;
cListHead = cListHead->link;
}
pListHead = pListHead->link;
}
}
// do breadth-first (level) traversal and print data
void ShowAll_BF(PNode* pListHead, ostream& outs)
{
PNode *ptr = pListHead;
while (ptr)
{
outs << ptr->data;
ptr = ptr->link;
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
//cnPtrQueue.h
#ifndef CN_PTR_QUEUE_H
#define CN_PTR_QUEUE_H
#include <cstdlib> // for size_t
#include <stack> // for STL stack template
#include "nodes_LLoLL.h" // for CNode
namespace cs3358Spring2014Assign06P1
{
class cnPtrQueue
{
public :
typedef std::size_t size_type;
cnPtrQueue();
bool empty() const ;
size_type size() const ; // returns # of items in queue
CNode* front();
void push(CNode* cnPtr);
void pop();
private :
std::stack<CNode*> inStack;
std::stack<CNode*> outStack;
size_type numItems; // # of items in queue
};
}
#endif
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
//cnPtrQueue.cpp
#include "cnPtrQueue.h"
#include <cassert>
using namespace std;
namespace cs3358Spring2014Assign06P1
{
cnPtrQueue::cnPtrQueue()
{
}
bool cnPtrQueue::empty() const
{
return outStack.empty() && inStack.empty();
}
size_t cnPtrQueue::size() const
{
return numItems;
}
CNode* cnPtrQueue::front()
{
assert(!inStack.empty() || !outStack.empty());
if (outStack.empty())
{
while (!inStack.empty())
{
outStack.push(inStack.top());
inStack.pop();
}
}
return outStack.top();
}
void cnPtrQueue::push(CNode * cnPtr)
{
inStack.push(cnPtr);
}
void cnPtrQueue::pop()
{
assert(!inStack.empty() || !outStack.empty());
if (outStack.empty())
{
while (!inStack.empty())
{
outStack.push(inStack.top());
inStack.pop();
}
}
outStack.pop();
}
}
Mar 26, 2014 at 8:21pm UTC
Mar 26, 2014 at 8:35pm UTC
Thank you so much. I knew I was missing something very simple.
Topic archived. No new replies allowed.