Bessjy not part of a class or namespace
MPD78
07-18-2009, 09:47 AM
Hello all,
I am not sure what to do with this error message that I recieve upon compiling. The message is;
Bessjy is not part of a class or a namespace.
This happens for each coefficient used in Bessjy, so I get 30 error messages. These are the only error messages that I recieve. I have only coded the Bessjy struct and coefficients. My thinking was that once I get this working correctly then I would work on the additional types of Bessel functions.
Can anyone help me out?
Thanks
Matt
davekw7x
07-18-2009, 11:26 AM
...once I get this working correctly...
Once you get what working correctly? Can you show your main() function where you were trying to do whatever...?
To print static data members, you don't need an object; just use the class name:
//
// Print some of the Bessjy coefficients
//
// davekw7x
//
#include "../code/nr3.h"
#include "../code/bessel.h"
int main()
{
cout << setprecision(15) << scientific;
for (int i = 0; i < 7; i++) {
cout << "Bessjy::j0r[" << i << "] = " << Bessjy::j0r[i] << endl;
}
return 0;
}
Output:
Bessjy::j0r[0] = 1.682397144220462e-04
Bessjy::j0r[1] = 2.058861258868952e-05
Bessjy::j0r[2] = 5.288947320067750e-07
Bessjy::j0r[3] = 5.557173907680151e-09
Bessjy::j0r[4] = 2.865540042042604e-11
Bessjy::j0r[5] = 7.398972674152181e-14
Bessjy::j0r[6] = 7.925088479679688e-17
Regards,
Dave
Footnote: Here is how the header file is organized as far as declaring and defining the j0r array:
// This stuff is in bessel.h
//
// The class definition
struct Bessjy {
.
.
.
static const Doub j0r[7], blah_blah_blah;
.
.
.
}; // The end of the class definition
// Outside the class definition
const Doub Bessjy::j0r[]={// seven double precision constants separated by commas };
Now try the main() that I show above.
MPD78
07-18-2009, 11:54 AM
What I meant by getting this to work correctly was simply getting results from the functions in the Bessjy struct and then working on the Bessik struct and so on. I can't show the code because it is all from the NR3 book and that can't be posted. The problem is occuring with all of the coefficients for the object Bessjy. These coefficients are in webnote 7 rev 1. The compilier produces an error for all 30 of them. The error is Bessjy is not a class or a namespace. Correcting that error is what I need help with.
davekw7x
07-18-2009, 12:00 PM
What I meant by getting this to work correctly was simply getting results from the functions in the Bessjy struct
I edited my previous post to show how I printed some of the coefficients. You are correct in saying that you aren't allowed to post copyrighted code, but what I meant (and should have said in the first place) was to post your main() function that uses the NR code.
When you are ready to test the Bessjy functions, declare an object, and then call the member functions for that object (you only need one object):
#include "../code/nr3.h"
#include "../code/bessel.h"
//
// Driver for routine bessjy
//
// davekw7x
int main()
{
Bessjy bessjy; // This object is used for all calculations
cout << fixed << showpoint;
for (Doub x = 1.0; x <= 5; x++) {
Doub z = bessjy.j0(x);
cout << "Bessjy.j0("<< x << ") = "
<< showpos << z << noshowpos;
z = bessjy.y0(x);
cout << ", Bessjy.y0("<< x << ") = "
<< showpos << z << noshowpos << endl;
}
cout << endl;
for (Doub x = 1.0; x <= 5; x++) {
Doub z = bessjy.j1(x);
cout << "Bessjy.j1("<< x << ") = "
<< showpos << z << noshowpos;
z = bessjy.y1(x);
cout << ", Bessjy.y1("<< x << ") = "
<< showpos << z << noshowpos << endl;
}
cout << endl;
for (Int n = 2; n <= 3; n++) {
for (Doub x = 1.0; x <= 5; x++ ) {
Doub z = bessjy.jn(n,x);
cout << "Bessjy.jn(" << n << ", " << x << ") = "
<< showpos << z << noshowpos;
z = bessjy.yn(n,x);
cout << ", Bessjy.yn("<< n << ", " << x << ") = "
<< showpos << z << noshowpos << endl;
}
cout << endl;
}
return 0;
}
Output
Bessjy.j0(1.000000) = +0.765198, Bessjy.y0(1.000000) = +0.088257
Bessjy.j0(2.000000) = +0.223891, Bessjy.y0(2.000000) = +0.510376
Bessjy.j0(3.000000) = -0.260052, Bessjy.y0(3.000000) = +0.376850
Bessjy.j0(4.000000) = -0.397150, Bessjy.y0(4.000000) = -0.016941
Bessjy.j0(5.000000) = -0.177597, Bessjy.y0(5.000000) = -0.308518
Bessjy.j1(1.000000) = +0.440051, Bessjy.y1(1.000000) = -0.781213
Bessjy.j1(2.000000) = +0.576725, Bessjy.y1(2.000000) = -0.107032
Bessjy.j1(3.000000) = +0.339059, Bessjy.y1(3.000000) = +0.324674
Bessjy.j1(4.000000) = -0.066043, Bessjy.y1(4.000000) = +0.397926
Bessjy.j1(5.000000) = -0.327579, Bessjy.y1(5.000000) = +0.147863
Bessjy.jn(2, 1.000000) = +0.114903, Bessjy.yn(2, 1.000000) = -1.650683
Bessjy.jn(2, 2.000000) = +0.352834, Bessjy.yn(2, 2.000000) = -0.617408
Bessjy.jn(2, 3.000000) = +0.486091, Bessjy.yn(2, 3.000000) = -0.160400
Bessjy.jn(2, 4.000000) = +0.364128, Bessjy.yn(2, 4.000000) = +0.215904
Bessjy.jn(2, 5.000000) = +0.046565, Bessjy.yn(2, 5.000000) = +0.367663
Bessjy.jn(3, 1.000000) = +0.019563, Bessjy.yn(3, 1.000000) = -5.821518
Bessjy.jn(3, 2.000000) = +0.128943, Bessjy.yn(3, 2.000000) = -1.127784
Bessjy.jn(3, 3.000000) = +0.309063, Bessjy.yn(3, 3.000000) = -0.538542
Bessjy.jn(3, 4.000000) = +0.430171, Bessjy.yn(3, 4.000000) = -0.182022
Bessjy.jn(3, 5.000000) = +0.364831, Bessjy.yn(3, 5.000000) = +0.146267
Regards,
Dave
MPD78
07-18-2009, 12:19 PM
The problem is not with passing arguments. It is with the compilier. The compilier doesn't like the Bessjy coefficients and I don't understand why. See attachment for a screen shot of the compilier error. If you can tell me how to correct this error that would be great.
Thanks
Matt
MPD78
07-18-2009, 12:23 PM
Also, here is my simple main() function.
int main()
{
Doub x,result;
x=1;
Bessjy myBessjy;
result = myBessjy.j0(x);
cout << "The value of Jo at " << x << " is " << result << endl;
return 0;
}
davekw7x
07-18-2009, 12:46 PM
...main() function....
Here's mine, where I show the relative paths to nr3.h and bessel.h on my system:
#include "../code/nr3.h"
#include "../code/bessel.h"
int main()
{
Doub x, result;
x = 1;
Bessjy myBessjy;
result = myBessjy.j0(x);
cout << "The value of Jo at " << x << " is " << result << endl;
return 0;
}
Output:
The value of Jo at 1 is 0.765198
Regards,
Dave
davekw7x
07-18-2009, 12:49 PM
The problem is not with passing arguments. It is with the compilier. The compilier doesn't like the Bessjy
Here is how the header file is organized as far as declaring and defining the j0r array:
// This stuff is in bessel.h
//
// The class definition
struct Bessjy {
.
.
.
static const Doub j0r[7], blah_blah_blah;
.
.
.
// Other stuff in the class definition
.
.
.
}; // The end of the class definition
// Outside the class definition
const Doub Bessjy::j0r[]={// seven double precision constants separated by commas };
Put the stuff in the header file in the order that I show.
Regards,
Dave
MPD78
07-18-2009, 12:57 PM
Dave,
Boy do I feel silly. I had the Bessjy coefficients located above the struct. Once I reversed the order all works like a charm.
If you are ever in the Pittsburgh area I shall have to buy you lunch.
Thanks a million.
Matt