Re: functional parameter error!
* Qiang Zhong:
On 3??13??, ????8??39??, "Alf P. Steinbach" <al...@start.no> wrote:
.....
Reproduce in a minimal program and post that complete code.
Cheers & hth.,
..
////////Complet code: //////////////////
#include "nr3.h"
void fgauss(const Doub x, VecDoub_I &a, Doub &y, VecDoub_O &dyda) {
}
struct Fitmrq {
static const Int NDONE=4, ITMAX=1000;
Int ndat, ma, mfit;
VecDoub_I &x,&y,&sig;
Doub tol;
void (*funcs)(const Doub, VecDoub_I &, Doub &, VecDoub_O &);
VecBool ia;
VecDoub a;
MatDoub covar;
MatDoub alpha;
Doub chisq;
Fitmrq(VecDoub_I &xx, VecDoub_I &yy, VecDoub_I &ssig, VecDoub_I &aa,
void funks(const Doub, VecDoub_I &, Doub &, VecDoub_O &), const Doub
TOL=1.e-3) : ndat(xx.size()), ma(aa.size()), x(xx), y(yy), sig(ssig),
tol(TOL), funcs(funks), ia(ma), alpha(ma,ma), a(aa), covar(ma,ma) {
for (Int i=0;i<ma;i++) ia[i] = true;
}
};
int main()
{
//VecDoub_I yy(
double tmp;
VecDoub xx(120);
VecDoub yy(120);
VecDoub ssigg(120);
VecDoub a(3);
void fgauss(const Doub, VecDoub_I, Doub, VecDoub_O);
Fitmrq mrq(&xx,&yy,&ssigg,&a,fgauss,0.000001);
return 1;
}
Ugh, I should never have asked...
This example may be complete, but it's decidedly /not/ minimal!
Anyways, remove those '&' address operators in your constructor call.
////////The file of "nr3.h" //////////////////
#ifndef _NR3_H_
#define _NR3_H_
Presumably this is from some "Numerical Recipes" book. Identifiers starting with
underscore followed by uppercase are reserved. Perhaps they know math, but not C++.
//#define _CHECKBOUNDS_ 1
//#define _USESTDVECTOR_ 1
//#define _USENRERRORCLASS_ 1
//#define _TURNONFPES_ 1
// all the system #include's we'll ever need
#include <fstream>
#include <cmath>
#include <complex>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
Inconsistent mixture of filename extension free headers and old C library headers.
using namespace std;
Should never be in a header (at least not placed in the global namespace).
// macro-like inline functions
template<class T>
inline T SQR(const T a) {return a*a;}
All uppercase should be reserved for macro names.
template<class T>
inline const T &MAX(const T &a, const T &b)
{return b > a ? (b) : (a);}
This is silly, header <algorithm> provides 'min' and 'max'.
inline float MAX(const double &a, const float &b)
{return b > a ? (b) : float(a);}
inline float MAX(const float &a, const double &b)
{return b > a ? float(b) : (a);}
template<class T>
inline const T &MIN(const T &a, const T &b)
{return b < a ? (b) : (a);}
inline float MIN(const double &a, const float &b)
{return b < a ? (b) : float(a);}
inline float MIN(const float &a, const double &b)
{return b < a ? float(b) : (a);}
template<class T>
inline T SIGN(const T &a, const T &b)
{return b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a);}
inline float SIGN(const float &a, const double &b)
{return b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a);}
inline float SIGN(const double &a, const float &b)
{return (float)(b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a));}
template<class T>
inline void SWAP(T &a, T &b)
{T dum=a; a=b; b=dum;}
This is silly, header <algorithm> provides 'swap'.
// exception handling
#ifndef _USENRERRORCLASS_
#define throw(message) \
{printf("ERROR: %s\n in file %s at line %d\n",
message,__FILE__,__LINE__); throw(1);}
#else
struct NRerror {
char *message;
char *file;
int line;
NRerror(char *m, char *f, int l) : message(m), file(f), line(l) {}
};
#define throw(message) throw(NRerror(message,__FILE__,__LINE__));
void NRcatch(NRerror err) {
printf("ERROR: %s\n in file %s at line %d\n",
err.message, err.file, err.line);
exit(1);
}
#endif
Using #if for customization is Bad.
Defining a keyword as a macro is Undefined Behavior if the code uses any
standard library header.
And jeez, this code sucks.
[Rest of that monstrosity snipped]
Cheers & hth.,
- Alf
--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!