On Jul 29, 6:45*am, "Amadeus W.M." <amadeu...@verizon.net> wrote:
> I wan to do this:
>
> #include <algorithm>
>
> //
> std::transform(Xj.begin(), Xj.end(), logXj.begin(), std::log);
> //
>
> where Xj and logXj are of type
>
> class Foo
> {
> public:
> * * * * typedef double * iterator;
> * * * * typedef const double * const_iterator;
>
> //
>
> };
>
> The compiler understandably gets confused by std::log, with the following
> error:
>
> fooMain.C:131: error: no matching function for call to ‘transform(double*,
> double*, double*, <unresolved overloaded function type>)’
> make: *** [main] Error 1
>
> How do I specify that I want
>
> double log(double) ?
>
> Thanks!
Just add a cast to the overloaded type you desire:
#include <algorithm>
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
vector<double> x;
x.push_back(10);
std::transform(x.begin(),x.end(),x.begin(),(double (*)(double))
std::log);
cout << *x.begin();
}
// Prints: 2.30259
|