Is it possible to omit initializing a struct
's member while initializing other members?
For example, this is my struct
struct person {
std::string name;
int age;
float weight;
};
And while initializing it, I want to skip initializing age
, but initialize the other members.
For example, I create a variable p
of type person
. This is how I would do it if I wanted to give values to all the members.
person p = {"harry", 25, 70};
Instead, I want to know if it is possible to omit giving the value '25' to age to the person p
(just for this particular structure variable) for the meanwhile and just give values to the other two. Like in for
loop we can skip any of the parameters by leaving it blank like this
for(int i=0;;i++)
I know that structs are not anywhere related to loops, I mentioned it just to explain what exactly do i mean by skipping the initialization of age
.