S
Simon Elliott
Let's say I have a small class:
class Noddy
{
private:
std::string s1_;
std::string s2_;
public:
Noddy();
};
Now let's say I want s1_ and s2_ to be initialised:
Noddy::Noddy():s1_("string1"),s2_("string2"){}
This is fine for a simple example, but if you have hundreds of data
items to construct, and if they are complex objects which need several
arguments, the whole thing starts to get a bit messy. Someone adds
s237a to the class, and they have to remember to add
s237a("string237a") to the list. And if they forget, the code still
compiles.
I'd quite like to be able to have all the data members declared and
initialised in one place. Sort of the equivalent of:
class Noddy
{
private:
std::string s1_("string1");
std::string s2_("string2");
public:
Noddy();
};
Any ideas?
class Noddy
{
private:
std::string s1_;
std::string s2_;
public:
Noddy();
};
Now let's say I want s1_ and s2_ to be initialised:
Noddy::Noddy():s1_("string1"),s2_("string2"){}
This is fine for a simple example, but if you have hundreds of data
items to construct, and if they are complex objects which need several
arguments, the whole thing starts to get a bit messy. Someone adds
s237a to the class, and they have to remember to add
s237a("string237a") to the list. And if they forget, the code still
compiles.
I'd quite like to be able to have all the data members declared and
initialised in one place. Sort of the equivalent of:
class Noddy
{
private:
std::string s1_("string1");
std::string s2_("string2");
public:
Noddy();
};
Any ideas?