I have a class with 5 variables: 2 strings, 2 doubles, and one int.
The user will always be able to provide at least one string and one double, but may not be able to supply the rest of the information, meaning default arguments should be included.
Of course, trying to create a bunch of constructors with all the arguments does not work - it fails to compile.
Say I try something like this instead:
Object(std::string s1, double d1) {
this->string1 = s1;
this->double1 = d1;
this->int1 = 0;
this->double2 = 0.0;
this->string2 = "foo";
}
Object(std::string s1, double d1, int i) {
this->string1 = s1;
this->double1 = d1;
this->int1 = i;
this->double2 = 0.0;
this->string2 = "foo";
}
// and so on...
This would be overloading the constructor, but are these still considered default arguments?
Is there a way to include every parameter in every constructor with default arguments? i.e., similar to this type of thing that doesn't work:
Object(std::string s1, double d1, int i = 0, std::string s2 = "foo", double d2 = 0.0) {
...
}
Object(std::string s1, double d1, int i, std::string s2 = "foo", double d2 = 0.0) {
...
}
// and so on...
The problem with this is that if the user only has 4 of the 5 values needed, at some point it would have to "skip" a parameter. For example, if I just used the first one, and the user didn't have the second string, there wouldn't be a way to go past it to pass the second double.