Hello, I have an issue with this code. If I do this
int _seg[5] = {ted.hour() / 10, ted.hour() % 10, ted.minute() / 10, ted.minute() % 10};
numPrint(_seg, 2);
it works, but when I do this
numPrint({ted.hour() / 10, ted.hour() % 10, ted.minute() / 10, ted.minute() % 10}, 2);
it throws
no matching function for call to ‘ClockShield::numPrint(<brace-enclosed initializer list>, int)’
Thanks for help!
vykašli se na to, smaž to a už nic nedělej
PS: smrdí ti nohy
MaximMaximS:
numPrint({ted.hour() / 10, ted.hour() % 10, ted.minute() / 10, ted.minute() % 10}, 2);
it throws
no matching function for call to ‘ClockShield::numPrint(, int)’
The function is probably expecting an int[]
and when you’re creating an array on the fly like that it’s technically a brace-enclosed intializer list and not an int[].
You can write the function to accept a std::initializer_list
, but that will cost more code space. (c++ - Brace-enclosed initializer list constructor - Stack Overflow ).
And can I somehow force it to be array?
Only if you assign the the brace-enclosed initializer list to an int[]
. There’s no other way that I know of.