Initialization ex performs copy initialization. It takes a value on the right and uses it to initialize the variable on the left. For members of a class class, the corresponding constructor is used. In your case, this means calling the copy constructor for SomeObject , but you made this constructor private, so the compiler is right to tell you that SomeObject::SomeObject is a private member that cannot be accessed.
Although the compiler is allowed to call the copy constructor and initialize ex.obj directly using the default constructor, this is an optional optimization; it should still be allowed to invoke the copy constructor.
You can either provide example_struct your own constructor, or use it instead of initializing the bracket, or you can publish the SomeObject copy constructor.
source share