Aug 11, 2011 at 2:05pm UTC
All set till compilation step.
All files are compiled.
I am getting this error while linking this project :(
"LinkedList_main.cpp:(.text+0x13a): undefined reference to `Linked_List<int>::~Linked_List()"
I am also getting this error wwhen I called other functions implemented like insert, display, delete, etc
// File Linked_List.h
template <class Object>
class Linked_List
{
private:
struct Node
{
Object info;
Node *next;
Node() : info(0), next(NULL)
{ }
};
Node *head;
Node *tail;
unsigned long size;
public:
Linked_List(): head(NULL), tail(NULL), size(0)
{ }
Node* create_node();
void free_node(Node *p);
void destroy_list();
~Linked_List();
};
//File Linked_List.cpp
#include <iostream>
#include "Linked_List.h"
using namespace std;
template <class Object>
void Linked_List<Object>::free_node(Node *p)
{
size--;
delete p;
}
template <class Object>
void Linked_List<Object>::destroy_list()
{
Node *temp;
while(head->next != NULL)
{
temp = head->next;
head->next = temp->next;
delete temp;
}
count = 0;
}
template <class Object>
Linked_List<Object>::~Linked_List()
{
destroy_list();
}
}
// File Main.cpp
#include <iostream>
#include "Linked_List.h"
using namespace std;
int main()
{
Linked_List<int> L1;
return 0;
}
Aug 11, 2011 at 2:10pm UTC
Template functions/classes can't go in .cpp files. You must put all function definitions in the header.
Aug 11, 2011 at 2:50pm UTC
Thanks, Problem Solved,
I am using gcc compiler for windows not VC++
so whenever I build this project using command line I get following msg from windows...
LinkedList_main.cpp has stopped working
Windows can check for problem solution online
Why is it so???
sth wrong with pointers???