Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ExistsInList template function

Status
Not open for further replies.

RichardF

Programmer
Oct 9, 2000
239
0
0
GB
Hi,

I am getting link error messages on the following function. VC7.

Any ideas ?
Thanks in Advance.
Rich.

Code:
template<class T>
bool ExistsInList(T Value, T Expr, ...)
{
	// NOTE: list terminates with -1
	va_list Argp;
	T chk = Expr;
	
	va_start(Argp,Expr);
	while (chk != Value)
		if (-1 == (int) (chk = va_arg(Argp,T)))
			break;
		
	va_end(Argp);
	
	return (chk == Value);
}

ATPModeTypes GetATPMode()
{
	return ATPMode;
}
...

if (ExistsInList<ATPModeTypes>(GetATPMode(),ATPSelfTestDone,ATPLongSelfTestMode,ATPShortSelfTestMode,-1)) {
  ....
}
(ATPModeTypes is an enum)

Here is the exact error message:
Linking...
RA_Control.obj : error LNK2019: unresolved external symbol "bool __cdecl ExistsInList<enum ATPModeTypes>(enum ATPModeTypes,enum ATPModeTypes,...)" (??$ExistsInList@W4ATPModeTypes@@@@YA_NW4ATPModeTypes@@0ZZ) referenced in function "void __cdecl ControlEventReceived(short,bool)" (?ControlEventReceived@@YAXF_N@Z)
.\Debug/RA.exe : fatal error LNK1120: 1 unresolved externals

 
Since that is a template function, did you put it inside the header file or in the source file(s) that use it? You must provide the entire function definition to the code that calls it to avoid linking errors with template classes and functions.
 
Hi,

The function was declared in stdafx.h, but the body was defined in stdafx.cpp.

Moving the body to the .h fixed the problem.

Thanks!
Rich.

Programmers are tools for converting caffeine into code
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top