hi, i need help.. i have been working for about 4 hours trying to figure this out and im still lost.. the answer is probably simple but im new to c++ so please forgive me. off a site called informit, the following code is posted:
#define NELEMS(A) (sizeof(A) / sizeof A[0])
struct math {
const char *name; // name of math function
double (*pmf)(double); // ptr to math function
};
math mtab[] = { // dispatch table
"sin", sin,
"cos", cos,
"exp", exp,
"tan", tan,
"sqrt", sqrt
};
//NELEMS(mtab) returns 5
"The NELEMS macro determines the number of elements in dispatch table mtab"
i can compile that code and the NELEMS macro function works without any problems. i tried rewriting some of the code in a program i have and im having issues determining the number of elements in mtab when i use the NELEMS function with a pointer from a class function where the structure member (mtab) is referenced.
//math *smath;
//myclass->smath points to mtab
(sizeof(myclass->smath) / sizeof(myclass->smath[0])
which returns 0 no matter what i do (i have 3 elements listed so it should be returning 3), i have no idea what im doing wrong.. if anyone can help id really appreciate it, thanks