c++ - how to add template parameter to global function? -
i'm working legacy code, , trying compile in linux. built in visual studio, compiler didn't keep standards. anyways, i'm going through code fixing , came across templated function declared globally. error:
/home/blah/blah;/blah.h:78: error: there no arguments ‘clip’ depend on template parameter, declaration of ‘clip’ must available
i have been able fix same error before when in specific scope doing myclass::clip. however, since has no scope, how resolve this?
updated: here's declaration of 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 clip:
src_row = clip( dst_row + h, 0, sr ); //dst_row + h, 0, sr int's... help? //btw, love quick responses, thanks.
the call , declaration in different '.h' files
put declaration of clip
somewhere before template definition caused error. if clip
not template, ordinary declaration do. if clip
function template , find definition of clip
, can copy start of definition , replace {...}
;
valid declaration.
edit: okay, you've found definition of clip
, let's in clip.h. , compile error in problem.h.
the best thing add #include <clip.h>
near top of problem.h. make sure both have guards against multiple #includes.
but might not work if introduces circular header dependency. if adding #include
causes different errors, can try putting declaration (not definition) of clip
in problem.h before definition gave error. part copy , paste , replace {...}
;
.
template<class t> inline t clip( t x, t bot, t top );
Comments
Post a Comment