template <class T>
class Edge开发者_如何学Python;
template <class T>
class Vertex;
template <class T>
class Vertex
{
T key;
char color;
std::vector<Edge> adjVertices;
};
template <class T>
class Edge
{
Vertex* source;
Vertex* target;
};
Gives me error in line: std::vector< Edge > adjVertices;
error: error C2143: syntax error : missing ';' before '<'
see reference to class template instantiation 'ds::Vertex<T>'
being compiled.
What should I change?
Your must
#include <vector>
and change
std::vector<Edge> adjVertices;
to
std::vector<Edge<T>> adjVertices;
The same applies to:
Vertex<T>* source;
Vertex<T>* target;
Next you'll face the problem that Vertex
is defined before Edge
. You should reverse the order.
This compiles:
#include <vector>
template <class T>
class Edge;
template <class T>
class Vertex;
template <class T>
class Vertex
{
T key;
char color;
std::vector<Edge <T> > adjVertices;
};
template <class T>
class Edge
{
Vertex <int> * source;
Vertex <int> * target;
};
精彩评论