I like the new automatically generated brace-enclosed initializers!
Is there any way I can avoid losing them if I start to declare my own constructors?
Code
#include <string>
struct Foo
{
int i;
std::string s;
// Foo() { } // I lose my brace-enclosed initializers if I uncomment this line
};
int
main( int argc, char* argv[] )
{
Foo f{ 1, "bar" }; // having the option to do this is good
return 0;
}
ANSWER
In light of juanchopanza's answer below, it looks like I must satisfy the lengthy rules for aggregates. But I still need a solution that I can apply to 50+ ORM classes (most with 5-15 fields each) that doesn't require a ton of boiler-plate code, or if there is boiler-plate code, at least it should be easy to edit/maintain.
The closest I could get was this solution using composition. I wonder if there is something better/simpler...
#include <string>
// this class must satisfy the rules for aggregates
struct Foo_
{
int i;
std::string s;
};
// this class can be anything...
struct Foo
{
Foo_ m_f;
Foo( Foo_ const& f ) : m_f( f ) { }
};
int
main( int argc, char* argv[] )
{
Foo f( { 1, "bar" } ); // ugly, but works
return 0;
}