|
Boost : |
From: brownell_at_[hidden]
Date: 2001-10-22 12:34:46
I don't think this is a problem with bind, but more of a C++ issue,
so my apologies if this is a bit off topic. I am passing a template
function to bind, and the resulting "bound" function is used as the
UnaryFunction in std::for_each. When I compile this application,
everything works as expected, but when the linker does its thing, it
can't find the template function. If I make a dummy call to the
template function, the function code is created and the linker is
happy. Is there a way I can make this all work without the dummy
call to the template function? I have a code example illustrating
the problem below.
Thanks in advance for your help!
Dave
#include<vector>
#include<algorithm>
#include "boost\bind.hpp"
template<class T>
bool TemplateFunction(T &t)
{
t = 2;
return(true);
}
int main(void)
{
std::vector<unsigned long> v;
v.resize(10);
//If this code segment is commented, it will not link. Uncomment
// to resolve the link error
/*{
unsigned long ulTemp;
TemplateFunction(ulTemp);
}*/
std::for_each(v.begin(), v.end(), boost::bind
(TemplateFunction<unsigned long>, _1));
return(1);
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk