how to specify overloaded function

A

Amadeus W.M.

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!
 
M

Mohammad Nabil Al-Aggan

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
 
I

Ian Collins

Amadeus said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top