I’m working with some legacy code, and trying to get it to compile in Linux. It was originally built in visual studio, whose compiler didn’t keep with standards. Anyways, now I’m going through the code fixing it and I came across a templated function that is declared globally. I get the error:
/home/blah/blah;/blah.h:78:
error: there are no arguments to
‘Clip’ that depend on a template
parameter, so a declaration of ‘Clip’
must be available
I have been able to fix this same error before when they were in a specific scope by doing myClass::Clip. However, since it has no scope, how do I resolve this?
Updated: here’s the declaration of the Clip function:
template<class T> inline T Clip( T x, T bot, T top )
{ return(( x>=bot && x<=top ) ? x : (( x<bot ) ? bot : top )); }
The call to Clip:
src_row = Clip( dst_row + h, 0, SR );
//dst_row + h, 0, SR are all int's... does that help?
//btw, love the quick responses, thanks.
The call and the declaration are in different ‘.h’ files
Put a declaration of
Clipsomewhere before the template definition that caused this error. IfClipitself is not a template, an ordinary declaration will do. IfClipis a function template and you find the definition ofClip, you can usually just copy the start of that definition and replace the{...}with a;to get a valid declaration.Edit: Okay, so you’ve found the definition of
Clip, let’s say in clip.h. And your compile error is in problem.h.The best thing to do is probably to add
#include <clip.h>near the top of problem.h. Make sure both have guards against multiple #includes.But that might not work if it introduces a circular header dependency. If adding the
#includecauses different errors, you can try just putting the declaration (not definition) ofClipin problem.h before the definition that gave the error. This would be the part where you just copy and paste and replace{...}with;.