|
-
May 13th, 2009, 05:05 PM
#1
I can get rid of an argument in Win32 console but not in....
My question is:
If I have this array:
Code:
double *x;
x= new double [5];
...if I want to copy this array to "xx" can I do xx=x; ?
If not, how has to be done?
If that's right.... I got an error when compiling...
Code:
'CMultilatera::f': function call missing argument list; use '&CMultilatera::f' to create a pointer to member
Multilatera is a class with an "f" function...
Code:
double CMultilatera::f (double *z);
general code:
Code:
double ynewlo;
double *start;
...
...
ynewlo = f ( start );
nelmin ( f, n, start, xmin, &ynewlo, reqmin, step, >>> line with error
konvge, kcount, &icount, &numres, &ifault );
I know there should be 1 argument when calling "f", but code worked correctly when I used it in a Win32 console without any classes at all. Problem came when I converted it to add classes.
PD: "nelmin" function is something from an external API so I dont' know what arguments to pass.. (I copied that problematic line as I was told in documentation)
Last edited by Shadowrun; May 13th, 2009 at 05:24 PM.
-
May 13th, 2009, 06:06 PM
#2
Re: "function call missing argument list; use '&function' to create a pointer to memb
...if I want to copy this array to "xx" can I do xx=x; ?
That would simply copy the value of a pointer variable from one to another assuming that your xx is declared as double* xx.
Use std::copy, provided that xx is pointing to a block of memory that is at least as big as the array pointed to by x. C arrays don't have assignment operators or copy constructors so it is your job to make sure that the destination array is big enough and if it is a pointer that memory has been allocated for it. That also assumes that you want to do a deep copy of the array.
http://cplusplus.com/reference/algorithm/copy/
Code:
std::copy(x, x + numElementsInX, xx);
I really can't help with the rest of the post. I don't follow what you are trying to do there at all. Without more details, I don't have a clue what you are trying to do. What is the declaration of the function that you are calling?
Last edited by kempofighter; May 13th, 2009 at 06:11 PM.
-
May 13th, 2009, 07:33 PM
#3
Re: "function call missing argument list; use '&function' to create a pointer to memb
Yes. Sorry, I've re-read my own message and it's a mess (I'm not English). 
Problem is that "f" function has 1 argument, but there's no problem when calling "f" without argument when I run the code in a Win32 app (imperative paradigm, no classes at all).
Nelmin is declared as:
Code:
void nelmin ( double fn ( double x[] ), int n, double start[], double xmin[],
double *ynewlo, double reqmin, double step[], int konvge, int kcount,
int *icount, int *numres, int *ifault )
"f" is supposed to be a mathematical function. Mine is:
Code:
double CMultilatera::f (double *z)
{
double residuo=0.0;
for (int i=1;i<=(M);i++)
{
residuo+=sqrt( (xx[i]-z[0])*(xx[i]-z[0]) + (yy[i]-z[1])*(yy[i]-z[1]) )-dd[i];
}
return (residuo);
}
But well... before getting that error .... I declared XX - YY -DD arrays as I explained before (with the "xx=x;" ).. so it might be the problem. ^^
I had to declared them as global, so this function can access them.
I'll try proper array copying. edit: Already done. I get same error.
Last edited by Shadowrun; May 13th, 2009 at 07:52 PM.
-
May 13th, 2009, 10:53 PM
#4
Re: "function call missing argument list; use '&function' to create a pointer to memb
I had to declared them as global, so this function can access them.
You can pass through function parameter.
Thanks for your help.
-
May 14th, 2009, 05:19 AM
#5
Re: "function call missing argument list; use '&function' to create a pointer to memb
This is suspiciously Java like.
Code:
double *x;
x= new double [5];
You can do this in C/C++
Or if the array must be dynamic, do it the C++ way.
Code:
#include <vector>
std::vector<double> x(5);
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
May 14th, 2009, 05:25 AM
#6
Re: "function call missing argument list; use '&function' to create a pointer to memb
This seems to be two questions in one, one regarding arrays/vectors and another regarding passing a member function as a parameter.
-
May 14th, 2009, 07:28 AM
#7
Re: "function call missing argument list; use '&function' to create a pointer to memb
OK.... problem with arrays is already fixed with "std:copy". Most important question is...
Is possible to call a function (which needs 1 argument) wihtout any argument??
What about the suggestion VS made: "use '&function' to create a pointer to member" ?
Documentation about that NELMIN and "f" function: http://people.sc.fsu.edu/~burkardt/c...47/asa047.html
If anyone wants to run my small .cpp for win32 app (VS 2008) which works with "f" being called without any argument...
http://telefonica.net/web/episodio1/algoritmo.zip
^^
Last edited by Shadowrun; May 14th, 2009 at 09:24 AM.
-
May 14th, 2009, 09:35 AM
#8
Re: "function call missing argument list; use '&function' to create a pointer to memb
 Originally Posted by Shadowrun
OK.... problem with arrays is already fixed with "std:copy". Most important question is...
Is possible to call a function (which needs 1 argument) wihtout any argument??
If you specify a default value for the function then you can call it without passing in an argument.
What I think you are looking for though here is a callback function, and there are differences between class member functions and standalone functions. If the callback requires a standalone function you cannot pass in a class member function (but you can pass in a static class member function, which is actually only a member by scoping and privelege reasons).
If the function requires a single parameter which is a void * pointer, which is common, then you can create a function like this:
Code:
return_type f( void * param )
{
MyClass * myclassPtr = static_cast< MyClass * >( param );
myclassPtr->memberFxn();
}
This is often what you need. If you need more data, eg MyClass and some other parameter information, then create a struct that has all that then use a function that casts the struct.
Use better names than above though in real code. Generally do not call your functions names like f.
Only use callbacks like this when working with third party APIs or if you are creating a C API. For C++ APIs that you are writing yourself, use polymorphism, either run-time or static (the latter when the class is known at compile time, and it generally means using templates). In C++0x there should hopefully be policy-based ways of doing it. (That also uses templates but gives better error messages if you use them wrong).
-
May 14th, 2009, 10:09 AM
#9
Re: "function call missing argument list; use '&function' to create a pointer to memb
"there are differences between class member functions and standalone functions."
Aaaahhh... ok, Nmtop. Thanks.
I have now:
Code:
double f( void * z )
{
CMultilatera * pMultilatera = static_cast< CMultilatera * >( z );
pMultilatera->memberFxn();
}
According to your code... where would I write my "f" function?
I'm student in physics doing final project. I've been learning C++ in my own, so I don't understand all the pointers stuff u have told me. 
"Use better names than above though in real code."
Sure, but "f" function was part of a .CPP i downladed, and I didn't want to change anything until it runs flawlessly
Last edited by Shadowrun; May 14th, 2009 at 10:17 AM.
-
May 14th, 2009, 10:27 AM
#10
Re: "function call missing argument list; use '&function' to create a pointer to memb
Code:
double f( void * z )
{
CMultilatera * pMultilatera = static_cast< CMultilatera * >( z );
pMultilatera->memberFxn();
}
If it's necessary to do this in a C++ application then I would say that you're design is seriously flawed!
Why can't you do this?
Code:
double f( CMultilatera &z)
{
z.memberFxn();
}
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
May 14th, 2009, 10:44 AM
#11
Re: "function call missing argument list; use '&function' to create a pointer to memb
I'm modifying a VisualC++ application which reads Wifi signals. I have to estimate distance to every spot and apply different location algorithms.
I coded a 2 algorithms and they run OK in final application (with classes). 3rd one needs an external function (NELMIN and its "f" function). Problem arised when I added that algorithm into VC++ application: I converted all functions to class function members.
How can I write that "f" function so I can call it inside a class member function?
Or should I avoid class implementation in my algorithms?
I dont know anything related to make optimized code. It's not important for my project, but my proffesor's idea was to make a class with all algorithms. 
I dont even know what's "memberFxn()", so I'll check it out.
Last edited by Shadowrun; May 14th, 2009 at 10:58 AM.
-
May 14th, 2009, 11:12 AM
#12
Re: "function call missing argument list; use '&function' to create a pointer to memb
We really need to see more than tiny snippets of code to be able to make an informed judgement of what the best course of action is.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
May 14th, 2009, 11:34 AM
#13
Re: "function call missing argument list; use '&function' to create a pointer to memb
(CMultilatera &z ) ??
"z" should be 'double' as I posted before:
"double CMultilatera::f (double *z) " or without classes: "double f (double *z) "
JohnWessex, I don't need the best action, but ANY action (as simple as possible). :P
Well... you've got an example in my .ZIP
There's full code for NELMIN and "f" function in previous link: http://people.sc.fsu.edu/~burkardt/c...47/asa047.html
This is my class .H
Code:
class CMultilatera
{
public:
CLaterationReturn Multilateracion(double* x, double* y, double* d, int cantidadAP, int melder);
private:
// function needed to send to NELMIN (NELDER-MEAD algorithm)
double f (double *z);
// functions for matrix operations
void MatInverse(double **x,double **a);
void Multip(double **mult, double **A, double **B,int M,int N, int K);
void Traspose(double **trasp, double **A);
int M;
};
But if there are doubts, I guess I'll add my algorithm without classes. No problem.
Last edited by Shadowrun; May 16th, 2009 at 12:49 PM.
-
May 15th, 2009, 03:56 AM
#14
Re: "function call missing argument list; use '&function' to create a pointer to memb
 Originally Posted by JohnW@Wessex
Code:
double f( void * z )
{
CMultilatera * pMultilatera = static_cast< CMultilatera * >( z );
pMultilatera->memberFxn();
}
If it's necessary to do this in a C++ application then I would say that you're design is seriously flawed!
Why can't you do this?
Code:
double f( CMultilatera &z)
{
z.memberFxn();
}
You would do the above so you can pass f to a C API for example as a thread function (although they don't normally return double).
-
May 15th, 2009, 04:08 AM
#15
Re: "function call missing argument list; use '&function' to create a pointer to memb
 Originally Posted by Shadowrun
If anyone wants to enlighten me about how to code the "f" standalone function inside a class, just for curiosity....
You may need to code 'f' as a static member function.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|