A bit of a basic question, but I'm having difficulty tracking down a definitive answer.
Are initializer lists the only way to initialize class fields in C++, apart from assignment in methods?
In case I'm using the wrong terminology, here's what I mean:
class Test
{
public:
Test(): MyField(47) { } // acceptable
int MyField;
};
class Test
{
public:
int MyField = 47; // invalid: only static const integral data members allowed
};
EDIT: in particular, is there a nice way to initialize a struct field with a struct initializer? For example:
struct MyStruct { int Number, const char* Text };
MyStruct struct1 = {}; // acceptable: zeroed
MyStruct struct2 = { 47, "Blah" } // acceptable
class MyClass
{
MyStruct struct3 = ??? // not acceptable
};