문제

In C i can do this:

ppackage ppnull() {
    return (ppackage) {
        .type = NULL
    }
}

However, in C++ I get syntax errors. I use the GNU g++ compiler. Is there a switch to enable this?

도움이 되었습니까?

해결책

With c++11 you can use initializer list:

struct ppackage
{
    void* type;
};

ppackage ppnull()
{
    return {nullptr};
}

Or just

ppackage ppnull()
{
    return {};
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top