我在vertex.h中有Vertex模板.从我的graph.h:
20 template<class edgeDecor, class vertexDecor, bool dir>
21 class Vertex;
Run Code Online (Sandbox Code Playgroud)
我在我的Graph模板中使用它.
我已经在我的Graph中成功使用了Vertex模板,返回指向Vertices的指针等.现在我第一次尝试声明并实例化一个Vertex对象,而gcc告诉我我的'声明符'是'无效'.怎么会这样?
81 template<class edgeDecor, class vertexDecor, bool dir>
82 Graph<edgeDecor,int,dir> Graph<edgeDecor,vertexDecor,dir>::Dijkstra(vertex s, bool print = false) const
83 {
84 /* Construct new Graph with apropriate decorators */
85 Graph<edgeDecor,int,dir> span = new Graph<edgeDecor,int,dir>();
86 span.E.reserve(this->E.size());
87
88 typename Vertex<edgeDecor,int,dir> v = new Vertex(INT_MAX);
89 span.V = new vector<Vertex<edgeDecor,int,dir> >(this->V.size,v);
90 };
Run Code Online (Sandbox Code Playgroud)
而且gcc说:
graph.h: In member function ‘Graph<edgeDecor, int, dir> Graph<edgeDecor, vertexDecor, dir>::Dijkstra(Vertex<edgeDecor, vertexDecor, dir>, bool) const’:
graph.h:88: error: invalid declarator before ‘v’
graph.h:89: error: ‘v’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
我知道这可能是另一个noob问题,但我会感激任何帮助.
伊戈尔是对的。至于下面的错误:
\n\ngraph.h:88: error: expected type-specifier before \xe2\x80\x98Vertex\xe2\x80\x99 \nRun Code Online (Sandbox Code Playgroud)\n\n...你可能需要说:
\n\nVertex<edgeDecor,int,dir> v = new Vertex<edgeDecor,int,dir>(INT_MAX);\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
7003 次 |
| 最近记录: |