开发者

C2143 in nested template class

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;
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜