Boost logo

Boost :

From: Amélie et François Dumont (francois.amelie_at_[hidden])
Date: 2003-02-20 16:25:01


Yet an other remark but this time about the answer of Graig Henderson to
Greg Dehass:

>>Greg,
>>From the Linker Error, it looks like you're using Microsoft Visual C++. I
>>discovered a bug recently with MSVC7.0 which may be the same as you're
>>seeing here, but it is reported to be fixed in Everett.
>>
>>The bug occurs if you pass a template function as a parameter to another
>>template function as a functor. The caller must specify the template
>>parameters explicitly, and the functor is called without any knowledge of
>>templates. However, if this is the only call to the functor with these
>>template parameters, then the compiler fails togenerate code for the
>>template and the linker fails with unresolved external.

>>Try adding a separate call to the function GenAlg::RouletteWheel(class
>>CGAController *) in a harmless piece of code to force the compiler to
>>generate the templated code.

You don't have to add a call to the function, that would be quite anoying to
find a right place in your code to do so. What Greg should do is an explicit
template instanciation writing this:

template unsigned long GenAlg::RouletteWheel<CGAController, unsigned
long>(CGAController*);

This way, you function will be instanciated even if it is not call, and
there is no more linking error.

Best Regards

"Greg Dehaas" <GregDehaas_at_[hidden]> wrote in message
news:430AD3105AC1D511B8990010B5C225C710ACBC_at_DMISERVER01...
> Hi all,
>
> Could someone please tell me how to achieve a functor binding to a
templated
> function?
>
> I have a namespace GenAlg with this inside:
> --------------------------------------------------------------------
> namespace GenAlg
> {
> template <class TController, class TFitness>
> unsigned long RouletteWheel(TController *oController)
> {
> ...
> }
> }
> --------------------------------------------------------------------
>
> elsewhere I have a
> --------------------------------------------------------------------
> boost::function1<unsigned long, CGAController *> fncSelection;
> --------------------------------------------------------------------
>
> I try to set fncSelection to RouletteWheel like so:
> --------------------------------------------------------------------
> fncSelection = boost::bind(GenAlg::RouletteWheel<CGAController, unsigned
> long>,_1);
> --------------------------------------------------------------------
>
> And my compiler's reply is:
> --------------------------------------------------------------------
> genetics.obj : error LNK2001: unresolved external symbol "unsigned long
> __cdecl GenAlg::RouletteWheel(class CGAController *)"
> (?RouletteWheel_at_GenAlg@@YAKPAVCGAController@@@Z)
> --------------------------------------------------------------------
>
> Help? Please?
> I'm sure this is stupid, simple stuff for you guys, and so annoying for me
> :)
> Greg
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk