1

I have a simple structure and I want a pointer-to-member c. I'm using MSVC2012 and if I don't declare the struct abc as a type definition (typedef), I can't use it.. how come?

struct abc
{
    int a;
    int b;
    char c;
};

char (struct abc)::*ptt1 = &(struct abc)::c; // Error: error C2144: syntax error : 'abc' should be preceded by ')'

typedef struct abc;
char abc::*ptt1 = &abc::c; // Compiles just fine
4

1 に答える 1

7

if I don't declare the struct abc as a type definition (typedef), I can't use it.. how come?

You can, and you don't need the struct keyword, nor the typedef. Just do this:

char abc::*ptt1 = &abc::c;
于 2013-03-21T12:50:32.697 に答える