Archived

This topic is now archived and is closed to further replies.

Linking Problems

This topic is 5115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, Im working on a simple gaming engine and I've ran into a problem that has become real annoying. Im trying to make my code flexible and easy to use, but it seems to not be working at the moment. Here's a few snippets (most having non important code clipped out):
template <typename Printer>
void PrintChar(int x, int y, DOUBLEWORD fontset, const char c, Printer& p);

template <typename Printer>
void PrintString(int x, int y, DOUBLEWORD fontset, const char* c, Printer& p);
namespace Printers
{
	struct ScreenPrint
	{
		CVideoSystem* v;

		ScreenPrint(CVideoSystem* vs) :
			v(vs)
		{}

		inline void operator ()(int x, int y, CImage* c)
		{
			v->BltImage(c, x, y, c->GetWidth(), c->GetHeight());
		}
	};
}
CFont f("arial.fnt");
f.PrintChar(5, 5, 0, 'o', Printers::ScreenPrint(video));
Basically it's a font class, and I pass a structure with an overloaded () operator in it that will be called for displaying the font in different ways (IE: to screen, to software image, special effects, etc) but here's where the problem comes: I get a linking error everytime I try to link the code telling me that "CFont:rintChar(int,int,unsigned int,char,struct Printers::ScreenPrint &)" is an unresolved external. The thing is that I have code very similar to this for blitting images elsewhere in my program, but I never get any errors for it. I've tried everything and the only way to stop the error is to wipe out the template idea, and just overload the function for every different method. Any help would be greatly appreciated! [edited by - porthios on December 15, 2003 9:21:10 PM]

Share this post


Link to post
Share on other sites
When using Visual C++, you can''t separate templated classes into headers and C++ files unless you #include the C++ files as well. Otherwise, you put everything in the .h file. It''s annoying, but I believe g++ doesn''t have this limitation.

~CGameProgrammer( );

-- Post screenshots of your projects. 100+ posts already in the archives.

Share this post


Link to post
Share on other sites
Oh, I did not know that. That seems kinda lame, but Ill have to put up with it for now. Does anyone know any workarounds for this? I don't like my header files having the implementation in them unless they're gonna be inline! Must. . . .Find . . .Another. . . .Way!!! :|

[edited by - porthios on December 15, 2003 9:34:11 PM]

Share this post


Link to post
Share on other sites