[SOLVED]Template Linker error - seperate files.
I'm getting this error
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl BlitArrayToConsole<struct _CHAR_INFO>(struct _CHAR_INFO (&)[45][80])" (??$BlitArrayToConsole@U_CHAR_INFO@@@@YAXAAY1CN@FA@U_CHAR_INFO@@@Z) referenced in function _main |
With the way I've designed a section in my code. I'm not to sure on how to let other files know about the template.
Heres the sections that are giving me this linker error.
header.h
1 2 3 4 5 6 7 8 9 10 11
|
#ifndef HEADER_H
#define HEADER_H
#include <windows.h>
#define WINDOW_HEIGHT_SIZE 45
#define WINDOW_WIDTH_SIZE 80
template <class TYPE>
void BlitArrayToConsole( TYPE (&OffScreenBuffer)[WINDOW_HEIGHT_SIZE][WINDOW_WIDTH_SIZE] );
#endif//HEADER_H
|
Sorry if any spellings wrong - this is a small snippet from my code I edited some of it for the posts.
Cheers,
Myth
header.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include "header.h"
template <class TYPE>
void BlitArrayToConsole( TYPE (&OffScreenBuffer)[WINDOW_HEIGHT_SIZE][WINDOW_WIDTH_SIZE] )
{
COORD offscreenBufferBuff;
offscreenBufferBuff.X = WINDOW_WIDTH_SIZE;
offscreenBufferBuff.Y = WINDOW_HEIGHT_SIZE;
COORD dest;
dest.X = dest.Y = 0;
SMALL_RECT rt;
rt.Top = 0;
rt.Bottom = WINDOW_HEIGHT_SIZE;
rt.Left = 0;
rt.Right = WINDOW_WIDTH_SIZE;
WriteConsoleOutput(GetStdHandle(STD_OUTPUT_HANDLE), &OffScreenBuffer[0][0], offscreenBufferBuff, dest, &rt);
}
|
main.cpp
1 2 3 4 5 6 7 8 9
|
#include "header.h"
void main()
{
//Temp Main
CHAR_INFO offscreenBuffer[WINDOW_HEIGHT_SIZE][WINDOW_WIDTH_SIZE];
BlitArrayToConsole <CHAR_INFO> ( offscreenBuffer );
}
|
Last edited on
You have to move the implementation of BlitArrayToConsole out of header.cpp and put it into header.h
In general template functions and classes should be implemented within the header.
Awesome I'll give that a try - I haven't used templates to much so they are new to me.
Thanks a heap jsmith ;)
Topic archived. No new replies allowed.