Given the example below, I was surprised to find that even though the default constructor was explicitly removable (or made by default in this regard), aggregate initialization remained possible.
#include <iostream>
struct DefaultPrivate
{
const int n_;
static const DefaultPrivate& create();
private:
DefaultPrivate() = delete;
};
const DefaultPrivate& DefaultPrivate::create()
{
static DefaultPrivate result{10};
return result;
}
int main() {
DefaultPrivate x;
DefaultPrivate y{10};
return 0;
}
Is the relationship between the private default construct (or remote) and aggregate initialization not specified in the standard?
This was on both GCC 6.3 and VCC 2017
The reason I ask the question was because I was hoping that changing access to the default constructor would prevent public aggregate initialization
source
share