Image

Imagestronae wrote in Imagecpp



If anyone can help me with the following, please feel free. I'm relatively new to C++ with templates, so please be gentle. :) I'm using MS VC++ 6.0 SP6.

I have the following three files:
// ----- begin trial.cpp
#include "stupid.h"
#include <iostream.h>
#include <stdio.h>

void main() {
holder<int> HI;
holder<double> HD;
HI.val = 5;
HD.val = 5.55;
display(HI);
display(HD);
}
// ----- end trial.cpp

// ----- begin stupid.h
template <class T> struct holder {
T val;
};

template <class T> void display(holder<T> h);
// ----- end stupid.h

// ----- begin stupid.cpp
#include "stupid.h"
#include <iostream.h>
#include <stdio.h>

template <class T> void display(holder<T> h)
{
cout << h.val << "\n" << flush;
}
// ----- end stupid.cpp

When I attempt to execute, they give me the following errors:
trial.obj : error LNK2001: unresolved external symbol "void __cdecl display(struct holder<double>)" (?display@@YAXU?$holder@N@@@Z)
trial.obj : error LNK2001: unresolved external symbol "void __cdecl display(struct holder<int>)" (?display@@YAXU?$holder@H@@@Z)

Yet if I put everything into one file, everything works fine. I have already made sure that the three files are already part of the project, so that's not the problem.

If anyone has insight, I'd greatly appreciate it -- my head hurts from banging it against the monitor. Thanks for reading!