0
Why do I get this error in 55 line
5 Respuestas
+ 3
zaya1235
see, initializer lists can be used to *implicitly* intialize structs, IF the elements match the types of the struct fields and the number of elements is equal to the number of struct fields. Example, if there a struct `Something`
struct Something {
std::string s;
int x;
};
the an initializer list of the form {std::string, int} can implicitly intialize this struct. For example,
Something func() {
return {std::string{"hello"}, 0};
}
these lines are perfectly valid as the returned list gets converted to struct `Something`. This is the reason your second code works.
Now in the first code, you need to return `Event` which has 2 fields of type std::string and int. But from the function, you are returning `{"NULL", 0, 0}`, which has 3 elements. So `Event` cannot be initialized from this. To fix the error, you need to return an intializer list of 2 elements rather than 3 (try removing the last 0)
+ 1
You need to return an `Event` from the function, but you're returning `{"NULL", 0, 0}` which is an initializer list.
+ 1
XXX thank you, I didn't notice that 0
0
XXX
https://code.sololearn.com/cLDmrOZo96Nu/?ref=app
Can you tell me why in this code it works
0
52 and 62 lines