On Mon, 23 Jun 2003 16:44:08 -0400, "zhou" <yz***@medplus.com> wrote:
Hi there,
We have a compiler specific issue which requires us to force template instantiation. This works fine.
Are you sure you're solving this issue in the best way? Using explicit
instantiation of STL stuff isn't a great idea. Perhaps you can
elaborate?
The problem comeswhen I try using std:find() on vector. Since vector has no member function find() and I have to use std::find(). The
linker fails on unsatisified symbols in find().
I think this is because find() is a template function and I have to force instantiation. However, I donot know the
correct syntax of doing so.
Any suggestions?
find has two template arguments, the iterator type, and the type of
the value to find. Assuming you've got a vector<int>, you need (in a
cpp file):
//deduces template arguments from signature
template
std::vector<int>::iterator
std::find<>(
std::vector<int>::iterator,
std::vector<int>::iterator,
int const&
);
template
std::vector<int>::const_iterator
std::find<>(
std::vector<int>::const_iterator,
std::vector<int>::const_iterator,
int const&
);
Alternatively, you could use find like this:
int* pos = find(&v.front(), &v.front() + v.size(), 10);
and then you'd be safe to instantiate like this:
template
int const* std::find<>(
int const*,
int const*,
int const&
);
template
int* std::find<>(
int*,
int*,
int const&
);
As you can see, implicit instatiation is definitely the way to go.
Tom