문제

What's the behavior of sizeof used in member initializer? I can't find a description about exactly that. In the below code example is it safe? ie, after struct member will the compiler put right size of A in b?

struct A
{
    int a = 0;
    int b = sizeof(A);
    int c = 3;
    int d = 4;
    char s[256];

    A()
    {
        //printf("b = %d\n", b);
    }
};
도움이 되었습니까?

해결책

The size of a struct is determined much earlier in the compilation than the setting of the values inside the struct.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top