473,396 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

cannot convert parameter from 'double (double)' to 'double (__cdecl *)(double)' error

When I compile code I get error
C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double
(double)' to 'double (__cdecl *)(double)'
in this part :
double Integration::quad2d(double (*func)(double,double))
{

nfunc = func ;

return qgaus(f1,x1,x2);//error there

}

//double (*nfunc)(double,double);

//double qgaus(double (*f)(double),double min,double max) const;

Please help
Jul 23 '05 #1
12 9838
I forgot
// double Integration::f1(double x)
Jul 23 '05 #2
What is f1? Your question is correct, but code you have provide is too
bad to understand where is a problem.

Jul 23 '05 #3

"Sydex" <sy****@comtv.ru> skrev i en meddelelse
news:cv**********@news.comcor-tv.ru...
When I compile code I get error
C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double
(double)' to 'double (__cdecl *)(double)'
The errormessage indicates that you should pass a pointer to a function, but
passed the function itself.
in this part :
double Integration::quad2d(double (*func)(double,double))
{

nfunc = func ;

return qgaus(f1,x1,x2);//error there
Try
return qgaus(&f1,x1,x2);
instead.

As an alternative, you might pass the function by reference.

/Peter
}

//double (*nfunc)(double,double);

//double qgaus(double (*f)(double),double min,double max) const;

Please help

Jul 23 '05 #4
Sydex wrote:
When I compile code I get error
C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double
(double)' to 'double (__cdecl *)(double)'
in this part :
double Integration::quad2d(double (*func)(double,double))
{

nfunc = func ;

return qgaus(f1,x1,x2);//error there
If 'f1' is a non-static member function, you won't be able to convert
it to a "pointer to function". Pointers to non-static members are not
compatible with pointers to functions. You need to rethink your code.

}

//double (*nfunc)(double,double);

//double qgaus(double (*f)(double),double min,double max) const;

Please help

V
Jul 23 '05 #5
Sydex wrote:
I forgot
// double Integration::f1(double x)

Is this a non-static member?
Jul 23 '05 #6
file "integration.h"
#ifndef INTEGRATION_H_

#define INTEGRATION_H_

class Integration

{

private:

double (*nfunc)(double,double);

double xsav;

double f1(double);

double f2(double);

double x1,y1,x2,y2;

int accuracy;

public:

Integration();

Integration(int naccuracy,double xx1,double xx2,double yy1,double yy2);

virtual ~Integration() { }

double qgaus(double (*f)(double),double min,double max) const;

double quad2d(double (*func)(double,double));

void SetIntLim(const double xx1,const double xx2,const double yy1,const
double yy2);

void SetAccuracy(const int naccuracy);

};

#endif

file "integration.cpp"

#include "stdafx.h"

#include "Integration.h"

Integration::Integration()

{

x1 = 0;

x2 = 1;

y1 = 0;

y2 = 1;

accuracy = 20;

}

Integration::Integration(int naccuracy,double xx1,double xx2,double
yy1,double yy2)

{

x1 = xx1 ;

x2 = xx2 ;

y1 = yy1;

y2 = yy2;

accuracy = naccuracy;

}

void Integration::SetAccuracy(const int naccuracy)

{

accuracy = naccuracy;

}

void Integration::SetIntLim(const double xx1,const double xx2,const double
yy1,const double yy2)

{

x1 = xx1 ;

x2 = xx2 ;

y1 = yy1;

y2 = yy2;

}

double Integration::qgaus(double (*f)(double),double min,double max) const

{

double sqrt3 = 1.7320508075688772935;

double step = (max - min)/accuracy;

double a,b = min;

double integral = 0;

if ((max - min) <= 0)

{

return 0 ;

}

for (int i=0;i<accuracy;i++)

{

a = b;

b +=step;

integral += ( (b-a)/2) * ( (*f)(-(b-a)/(2*sqrt3)+ (a+b)/2 ) + (*f)(
(b-a)/(sqrt3*2) + (a+b)/2 ));

}

return integral;

}

double Integration::quad2d(double (*func)(double,double))

{

nfunc = func ;

return qgaus(f1,x1,x2);

}

double Integration::f1(double x)

{

xsav = x ;

return qgaus(f2,y1,y2);

}

double Integration::f2(double y)

{

return nfunc(xsav,y);

}

"SnaiL" <VL********@MIRATECH.BIZ> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
What is f1? Your question is correct, but code you have provide is too
bad to understand where is a problem.

Jul 23 '05 #7
Sydex wrote:
double f1(double);
double qgaus(double (*f)(double),double min,double max) const;

return qgaus(f1,x1,x2);

f1 is a non-static member. You can not convert non-static member
functions to pointers to regular functions. It would appear
that your f1 function doesn't depend at all on the Integration
instances. Just declare it static:

static double f1(double);
Jul 23 '05 #8
Victor Bazarov wrote:
If 'f1' is a non-static member function, you won't be able to convert
it to a "pointer to function". Pointers to non-static members are not
compatible with pointers to functions. You need to rethink your code.


Why? Can't he just use an adaptor? Like std::mem_fun_ref or such?

--
Regards,
Matthias
Jul 23 '05 #9
Matthias wrote:
Victor Bazarov wrote:
If 'f1' is a non-static member function, you won't be able to convert
it to a "pointer to function". Pointers to non-static members are not
compatible with pointers to functions. You need to rethink your code.

Why? Can't he just use an adaptor? Like std::mem_fun_ref or such?


They are functors. If the target for this adaptation is not a template,
it won't be able to pick it up. Consider

int foo(int (*f)()) // not a template
{
return f();
}

template<class F> int bar(F f) // a template
{
return f();
}

int fubar() // function
{
return 42;
}

struct barf // functor (like adaptors)
{
int operator()() { return 666; }
};

int main()
{
foo(fubar); // fine
bar(fubar); // fine
barf b;
foo(b); // error
bar(b); // fine
}

See the recent thread about passing a functor to 'qsort' in c.l.c++.m

Victor
Jul 23 '05 #10
Matthias wrote:
Victor Bazarov wrote:
If 'f1' is a non-static member function, you won't be able to convert
it to a "pointer to function". Pointers to non-static members are not
compatible with pointers to functions. You need to rethink your code.


Why? Can't he just use an adaptor? Like std::mem_fun_ref or such?


An adaptor would convert member function pointer to functional object.
The OP needs to convert member function pointer to regular function
pointer. The latter is cannot be done by standard means in C++. There
are platform-specific implementations that can do that, but this is a
completely different story.

--
Best regards,
Andrey Tarasevich
Jul 23 '05 #11
Andrey Tarasevich wrote:
Matthias wrote:
Victor Bazarov wrote:

If 'f1' is a non-static member function, you won't be able to convert
it to a "pointer to function". Pointers to non-static members are not
compatible with pointers to functions. You need to rethink your code.


Why? Can't he just use an adaptor? Like std::mem_fun_ref or such?

An adaptor would convert member function pointer to functional object.
The OP needs to convert member function pointer to regular function
pointer. The latter is cannot be done by standard means in C++. There
are platform-specific implementations that can do that, but this is a
completely different story.


Hm, this qgaus function is his own function right? Why not just change
the first parameter to take a function object instead of a ptr to
function? ^^

Am I missing something?
--
Regards,
Matthias
Jul 23 '05 #12
Matthias wrote:
[...]
Hm, this qgaus function is his own function right? Why not just change
the first parameter to take a function object instead of a ptr to
function? ^^

Am I missing something?


I think so. If you change it to an object (or a reference), then it
will be unable to accept function pointers. Unless it is converted
into a template, there is no accepting both function pointers and
functors. See my other reply if you haven't already.

V
Jul 23 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
0
by: Frank King | last post by:
Hi, I am using CArray and quick sort funciton to sort an array of double type of data points. I found an article in MSDN HOWTO: Quick Sorting Using MFC CArray-Derived Classes ID: Q216858 ...
1
by: Gary | last post by:
I have a strange compile error. C2664 cannot convert parameter 2 from int to int... Earlier in my code I was setting up my dataset... I add an int field like so... ...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
11
by: wuzertheloser | last post by:
Write a program which calculates the integral of the function f(x)=(A*x^m)/n! on the interval from a to b (0<a<b). In the main program, scanf a double value for m and a...
2
by: Angus | last post by:
Hello I have some classes defined in shapes.h and use them like this: const IShape* rectangle = new Rectangle(10.0, 20.0); // width, height cout << rectangle->calculateArea() << endl; ...
22
by: xiao | last post by:
Can I fullfill this task? Using fred and fwrite?
2
by: Frostmur | last post by:
Hi !! I'm trying to convert C code to C++. This is my function: static void (*selection)(void) = NULL; static void (*pick)(GLint name) = NULL; void zprSelectionFunc(void (*f)(void))
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.