473,851 Members | 2,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

nfunc = func ;

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

}

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

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

Please help
Jul 23 '05 #1
12 9899
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.r u> skrev i en meddelelse
news:cv******** **@news.comcor-tv.ru...
When I compile code I get error
C2664: 'Integration::q gaus' : 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::qu ad2d(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),do uble min,double max) const;

Please help

Jul 23 '05 #4
Sydex wrote:
When I compile code I get error
C2664: 'Integration::q gaus' : cannot convert parameter 1 from 'double
(double)' to 'double (__cdecl *)(double)'
in this part :
double Integration::qu ad2d(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),do uble 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 "integratio n.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,doubl e xx1,double xx2,double yy1,double yy2);

virtual ~Integration() { }

double qgaus(double (*f)(double),do uble 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(con st int naccuracy);

};

#endif

file "integration.cp p"

#include "stdafx.h"

#include "Integratio n.h"

Integration::In tegration()

{

x1 = 0;

x2 = 1;

y1 = 0;

y2 = 1;

accuracy = 20;

}

Integration::In tegration(int naccuracy,doubl e xx1,double xx2,double
yy1,double yy2)

{

x1 = xx1 ;

x2 = xx2 ;

y1 = yy1;

y2 = yy2;

accuracy = naccuracy;

}

void Integration::Se tAccuracy(const int naccuracy)

{

accuracy = naccuracy;

}

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

{

x1 = xx1 ;

x2 = xx2 ;

y1 = yy1;

y2 = yy2;

}

double Integration::qg aus(double (*f)(double),do uble min,double max) const

{

double sqrt3 = 1.7320508075688 772935;

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::qu ad2d(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********@MIR ATECH.BIZ> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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),do uble 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_re f 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_re f 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

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

Similar topics

5
22088
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 example). int foo(const char* argv) { return 0; } int main(int argc, char* argv) {
8
5486
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
0
3707
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 The article works well with CStringArray. But when I wrote the following code about double type. It does not work for
1
3746
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... Books->Columns->Add("Volume",System::Type::GetType(S"System.Int32")); Then below I try to add an int value to it.
12
10099
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 it. here is the 4 errors. c:\C++\Ch15\Employee.h(29): error C2440: '=' : cannot convert from 'char ' to 'char '
11
4411
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 non-negative integer value for n, a double value of A, and positive double values for a and b>a. Call the function Intgr() to evaluate the integral. Your main program should be followed by three functions:
2
7260
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; delete rectangle; // causes error C2665 error
22
11800
by: xiao | last post by:
Can I fullfill this task? Using fred and fwrite?
2
13222
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
9898
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11020
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10735
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9506
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7907
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5736
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4549
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4143
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.