Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how to specify overloaded function

Reply
Thread Tools

how to specify overloaded function

 
 
Amadeus W.M.
Guest
Posts: n/a
 
      07-29-2009
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!

 
Reply With Quote
 
 
 
 
Mohammad Nabil Al-Aggan
Guest
Posts: n/a
 
      07-29-2009
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



 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      07-29-2009
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Passing a function pointer as an argument to an overloaded >> operator. glen stark C++ 3 09-30-2003 08:25 AM
why does my complier complain there is an overloaded function? Roy Yao C++ 4 08-21-2003 09:35 AM
operator= - code in overloaded function doesn't get called Tobias Langner C++ 2 07-31-2003 09:22 AM
Why can't '='(Assignment) operator be overloaded as friend function ? Nitin Bhardwaj C++ 8 07-14-2003 03:50 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57