473,394 Members | 1,748 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,394 software developers and data experts.

Puntatori a funzioni

Un saluto a tutti, ho il seguente problema:
ho definito una funzione che trova lo zero di una funzione con il
metodo delle secanti, in un file cpp:

double secant (double (*f)(double), double x0, double x1)
{
[...]
}

ed il relativo header file:

double secant (double (*f)(double), double x0, double x1);

ho inoltre definito una classe che comprende tra le funzioni membro le
seguenti:

void CmyClass::calcola(void)
{
double x,y;
x = secant(&CmyClass::eq_prova,-2,10);

y = eq_prova(x);
}

double CmyClass::eq_prova(double x)
{
return (x - 4) * (x + 5);
}

Al momento della compilazione della classe mi viene mostrato
quest'errore:

c:\.....\myclass.cpp(28) : error C2664: 'secant' : cannot convert
parameter 1 from 'double (__thiscall CmyClass::* )(double)' to 'double
(__cdecl *)(double)'

potete aiutarmi? Grazie in anticipo.

Mar 17 '06 #1
2 3078
* massi:
[italian]
Please post english to this international group, since most of us here
don't understand italian.

Use an italian national group such as, presumably, [it.comp.lang.c++],
for C++ language discussions in italian.

Thank you,

- The kind off-topicality bobby

Un saluto a tutti, ho il seguente problema:
...


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 17 '06 #2
massi wrote:
double secant (double (*f)(double), double x0, double x1);

ho inoltre definito una classe che comprende tra le funzioni membro le
seguenti:

void CmyClass::calcola(void)
{
double x,y;
x = secant(&CmyClass::eq_prova,-2,10);

y = eq_prova(x);
}

double CmyClass::eq_prova(double x)
{
return (x - 4) * (x + 5);
}

Al momento della compilazione della classe mi viene mostrato
quest'errore:

c:\.....\myclass.cpp(28) : error C2664: 'secant' : cannot convert
parameter 1 from 'double (__thiscall CmyClass::* )(double)' to 'double
(__cdecl *)(double)'


A member function gets passed an additional parameter, the this pointer
to the underlying object. Since your computation function eq_prova does
not use any data member from CMyClass, you can simply make it "static".
(Maybe you need to add "extern C", too)

Christian

Mar 17 '06 #3

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

Similar topics

3
by: lamilla | last post by:
Salve a tutti, sto creando una applicazione che istanzia un thread al quale viene passato come argomento il puntatore ad una classe che contiene molte funzioni alcune delle quali devono essere...
1
by: Cloud Strife | last post by:
Salve ragazzi, qualcuno mi saprebbe indicare dove posso trovare i prototipi delle funzioni della classe string (magari se c'e' scritto come si usano e meglio^_^) ? please non mi dite di andare a...
18
by: cs | last post by:
This is the function malloc_m() that should be like malloc() but it should find memory leak, and over bound writing in arrays. How many errors do you see? Thank you...
6
by: TC | last post by:
Hi. I write a program in c language that read a text file and extrapolate the word. for all word the program calculate the number of the times that word is present in the text. The problem is the...
3
by: TC | last post by:
I'm not a C programmer. This is a good C? how check the return value of getch or scanf? and how check for the \n at the end of the text read? FEOF do not return true if the file (text file) is...
2
by: T-Mat | last post by:
Ciao a tutti!!!! Devo creare un'oggetto riutilizzabile che abbia le funzioni di modifica,aggiunta,eliminazione e scrittura di elementi in un file XML utilizzando il linguaggio C#. Una volta...
0
by: Elvandar | last post by:
<p> Hi all. I've a web application running under tomcat 5.0.28. Sometimes, after a couple of days of 24h running of the server, suddenly it becames impossibile to log in the application, until...
52
by: ¬a\\/b | last post by:
is it possible that a malloc function that use a nobody student is better than all yours :) How many errors do you see? Bug1: memory<13MB Bug2: it seems do you have to write you own sprintf...
3
by: Obelix | last post by:
Premetto, che è un po' che non uso il C++, per il semplice fatto che sono passato a java. Adesso devo fare un lavoro di manutenzione su una libreria che avevo scritto parecchi anni fa. La...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.