Convert a pointer to a data item in void *

I know that I can get a pointer to a data element for a class or structure, but the last line of the following code does not compile:

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

int main()
{
    typedef struct abc abc;
    char abc::*ptt1 = &abc::c;
    void *another_ptr = (void*)ptt1;
}

Why can't I convert ptt1 to another_ptr? We are talking about pointers, so one pointer should have the same size as the other (although conceptually different)

+5
source share
3 answers

; -. *. , .* ->*. , , , *?

void* (§4.10):

" cv T", T , prvalue " cv void".

, , , "" (§3.9.2):

, , "", .

+10

, , , . , void*, . , , size_t, a void* , a size_t. , , . , , , , , .

void* . , ( a char*), ( - ).

+2

Are you trying to do something like this?

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

int main()
{
    ABC abc;
    char *ptt1 = &abc.c;
    void *another_ptr = (void*)ptt1;
}
0
source

All Articles