0

Compilation error in this solution to a codechef problem [RIGHTRI]. (I am using pythagoras theorem to solve it)

Link to question: https://www.codechef.com/problems/RIGHTRI I keep getting a compilation error : prog.cpp: In function ‘int main()’: prog.cpp:13:35: warning: narrowing conversion of ‘(std::pow<int, int>((x2 - x1), 2) + std::pow<int, int>((y2 - y1), 2))’ from ‘__gnu_cxx::__promote_2<int, int, double, double>::__type {aka double}’ to ‘int’ inside { } [-Wnarrowing] int dSq[3] = {pow(x2-x1,2)+pow(y2-y1,2),pow(x3-x2,2)+pow(y3-y2,2),pow(x1-x3,2)+pow(y1-y3,2)}; https://code.sololearn.com/cN4D9y8KQUq4/?r

29th Mar 2018, 8:43 AM
illusion
illusion - avatar
2 Respuestas
+ 2
Thats not the error in your code, thats just the warning part. The error is in the sort function call. You pass the first and the last element of the array as parameters, while the function requires iterators which can be used to deduce addresses of the array elements. So you need to change the call to : sort(dSq, dSq+3); // This will sort the complete array
29th Mar 2018, 12:16 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
thank you so much!
29th Mar 2018, 12:31 PM
illusion
illusion - avatar