tags:

views:

106

answers:

3

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
 {

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?

+2  A: 

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>::
GMan
This does not seem to be a problem, after following sth's advice that error disappeared.
nieldw
+2  A: 

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

f4
+6  A: 

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.

sth