Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to specify overloaded function

0 views
Skip to first unread message

Amadeus W.M.

unread,
Jul 28, 2009, 11:45:44 PM7/28/09
to
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!

Mohammad Nabil Al-Aggan

unread,
Jul 29, 2009, 12:29:32 AM7/29/09
to

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

Ian Collins

unread,
Jul 29, 2009, 1:50:48 AM7/29/09
to
Amadeus W.M. wrote:
> I wan to do this:
>
> #include <algorithm>
>
> //
> std::transform(Xj.begin(), Xj.end(), logXj.begin(), std::log);
> //
>
> How do I specify that I want
>
> double log(double) ?
>
The problem is probably cased by std::log having the wrong linkage
(extern "C" for use in the C world).

Either use a wrapper, or a cast.

--
Ian Collins

0 new messages