Discussion:
"Function cannot be member of struct" error ...
(too old to reply)
Russell Potter
2011-03-20 09:28:37 UTC
Permalink
I have a typedef to a functioon as follows:

"typedef int ( *x)()"

Then, later, the structure declaration:

"struct y {

z x;
};"

But, trouble is, the line on which of the
"z" field declaration yoccurs ields the
error:

"<unknown>: function cannot the mem-
ber of struct y"

Does sanyone know the causes and
possible solutions to this this error?

Thanks,
Russell
David Lowndes
2011-03-20 09:34:59 UTC
Permalink
Post by Russell Potter
"typedef int ( *x)()"
"struct y {
z x;
};"
But, trouble is, the line on which of the
"z" field declaration yoccurs ields the
"<unknown>: function cannot the mem-
ber of struct y"
Russell,

What's z in your example?

Did you mean to write:

typedef int ( *z)();

struct y
{
z x;
};

... which compiles fine for me?
... or something completely different?

Please show just enough of your real code.

Dave
Russell Potter
2011-03-20 10:11:23 UTC
Permalink
Dave,

I didn't want to use the real code for the sake
of simplicity, but I'll do so if it makes things
typedef struct bdic_icdes *bdev_cmple_fn(
struct bd_allocs *allocs,
struct bd_logger *logger);
(Where "bd_logger" and "bd_allocs" are
a pluggable memory allocator and error
logger, respectively)

and the later structure declaration is as
follows
struct bdev_op {
enum bdev_asscs assc;
int prec;
bdev_cmple_fn cmple;
};
where the problematic field is
"cmple"

Hope this helps,
Rissell
Russell Potter
2011-03-20 17:03:07 UTC
Permalink
Dave,

l had a sudden epiphany about this problem:
that there might have been an operator prece-
dence error in ythe typedef so I added an
extra set the parentheses to make my intent
typedef struct bdic_icdes *(* bdev_cmple_fn) (
                struct bd_allocs *allocs,
                struct bd_logger *logger);
And that seems to have fixed things (thanks
*very* much for helping with this :-)

At least part of the reason I made such a
basic rror is that I've lost part of my
eyesight due to a stroke (I do this progra-
mming as sorely needed mental exercise -
to deal with the brain damage), so I literally
couldn't see what was going :-)

Russell
David Lowndes
2011-03-20 23:58:12 UTC
Permalink
Post by Russell Potter
At least part of the reason I made such a
basic rror is that I've lost part of my
eyesight due to a stroke (I do this progra-
mming as sorely needed mental exercise -
to deal with the brain damage), so I literally
couldn't see what was going :-)
I'm glad you've resolved the issue, and sad to hear of your problems
:(

Unfortunately not being able to see the wood for the trees in many C++
error messages isn't something that requires such an affliction to be
problematic.

Take care
Dave

Loading...