开发者

Why won't C++ allow this default value?

Why won't GCC allow a default parameter here?

 template<class edgeDecor, class vertexDecor, bool dir>
 Graph<edgeDecor,int,dir> Graph<edgeDecor,vertexDecor,dir>::Dijkstra(vertex s, bool print = false) const
 {
开发者_StackOverflow中文版

This is the output I get:

graph.h:82: error: default argument given for parameter 2 of ‘Graph<edgeDecor, int, dir> Graph<edgeDecor, vertexDecor, dir>::Dijkstra(Vertex<edgeDecor, vertexDecor, dir>, bool)’
graph.h:36: error: after previous specification in ‘Graph<edgeDecor, int, dir> Graph<edgeDecor, vertexDecor, dir>::Dijkstra(Vertex<edgeDecor, vertexDecor, dir>, bool)’

Can anyone see why I'm getting this?


You seem to already have declared the function (including the default parameter) in graph.h, line 36. Don't repeat the default value in the function implementation, specifying it one time in the declaration is enough.


You've specified one of the template parameters:

Graph<edgeDecor,int,dir> Graph<edgeDecor,vertexDecor,dir>::
                ^^^

Change it to match:

Graph<edgeDecor,vertexDecor,dir> Graph<edgeDecor,vertexDecor,dir>::


default arguments must be given only in the declaration of your method, not the definition

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜