C ++ неопределенная ссылка на метод класса шаблона [дубликат]
На этот вопрос уже есть ответ здесь:
Почему я получаюнеразрешенный внешний символ » ошибки при использовании шаблонов? [Дубликат] 3 ответаНеопределенная ссылка на членов шаблона 1 ответЯ всегда получаю
неопределенная ссылка на `Graph :: InsertVertex (std :: string) '
если я скомпилирую свой проект! Любые намеки, почему он не может решить эту ссылку? (все файлы находятся в папке проекта netbeans)
//main.cpp
#include
#include
#include "Graph.h"
using namespace std;
int main(int argc, char** argv)
{
Graph *graph = new Graph(); // InsertVertex("A");
return 0;
}
//node.h
#include
#include "Graph.h"
template
class Node
{
friend class Graph;
public:
Node(T val)
{
this->data = val;
this->vertList = NULL;
this->next = NULL;
}
Node(const Node& orig);
virtual ~Node();
private:
T data;
Node *vertList;
Node *next;
int status;
};
//Graph.h
#include
#include "Node.h"
template
class Graph
{
public:
Graph()
{
head = NULL;
}
void InsertVertex(T val);
void InsertEdge(T v_val, T e_val);
void PrintVertices();
void PrintEdges(T v_val);
void DeleteEdge(T v_val, T e_val);
void DeleteVertex(T val);
void bfs();
private:
Node *head;
};
//Graph.cpp
#include "Graph.h"
template
void Graph::InsertVertex(T val)
{
Node *temp = new Node(val);
if(head == NULL) head = temp;
else
{
Node node = head;
while(node->vertList != NULL)
node = node->vertList;
node->vertList = temp;
}
}
template
void Graph::InsertEdge(T v_val, T e_val)
{
if (head != NULL)
{
Node *k = head;
Node *t = head;
Node *temp = new Node (e_val);
while (t != NULL)
{
if (t->data == v_val)
{
Node *s = t;
while (s->next != NULL)
s = s->next;
s->next = temp;
while (k != NULL)
{
if(k->data == e_val) break;
k = k->vertList;
}
temp->vertList = k;
return;
}
t = t->vertList;
} // end while loop
}
else std::cout < "Add first vertices to the graph" < std::endl;
}
template next != NULL)
{
std::cout < t->next->vertList->data < " ";
t = t->next;
}
}
t = t->vertList;
}
}
template