C++ Compound literal
-
12-11-2019 - |
Question
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?
Solution
With c++11
you can use initializer list:
struct ppackage
{
void* type;
};
ppackage ppnull()
{
return {nullptr};
}
Or just
ppackage ppnull()
{
return {};
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow