Question

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
Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top