imagine I have
struct Foo
{
int a;
string s;
float f;
}
So now when I need to create new Foo I need to add a constructor:
struct Foo
{
int a;
string s;
float f;
Foo(int a, string s, float f)
{
this->a = a;
this->s = s;
this->f = f;
}
}
However this method of manually writing constructors is really time consuming, especially with structs/classes with 10+ properties. My questions is: Is there a way to automatically generate such constructors?
struct Foo
{
int a;
std::string s;
float f;
};
Foo f{42,"Foo",0.0};
works just fine, but a constructor gives you more control e.g. check of init value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With