这是我的课:
template <class T>
class Vertex
{
private:
T data;
Vertex<T>* next;
public:
friend class Graph;
Vertex(T dat, Vertex<T>* nex)
{
data=dat; next = nex;
}
};
template <class T>
class Graph
{
public:
Vertex<T>* head;
Graph() : head(NULL)
{
}
void insert(T data)
{
Vertex<T>* ptr = new Vertex<T>(data, head);
head = ptr;
}
};
主要:
int main()
{
Graph<int> graph;
graph.insert(1);
}
当我编译它告诉我这个:
graph.h: In instantiation of ‘Vertex<int>’:
graph.h:30: instantiated from ‘void Graph<T>::insert(T) [with T = int]’
main.cpp:6: instantiated from here
graph.h:10: error: template argument required for ‘struct Graph’
是什么导致了这个问题?