c++ - Loop using a template variable not working? -


here situation:

i made function called myfunction

myfunction accepts 2 arrays using parameter definitions template<std::size_t n1, std::size_t m1, std::size_t n2, std::size_t m2>.

then made myfunction follows:

void myfunction(double (&w)[n1][m1],double (&td)[n2][m2]){  

and in myfunction have for loop for(int i; i<n1; i++){...}.

it won't compile , there has warning saying:

warning: comparison between signed , unsigned integer expressions.

i don't know warning means. if knows why happening please help. :)

std::size_t unsigned type , int signed type. warning clear: trying compare i, of signed type, n1, of unsigned type. , presumably have -werror turned on or that.

the reason why warning exists can counterintuitive results. example, -1 < (std::size_t)(0) false, since -1 converted std::size_t , end large positive value. (technically, happens because relational operators perform usual arithmetic conversions, favour unsigned types on signed types of equal or lesser width.)

however, many people disable warning, because use of int loop control variable extremely common , benign. make sure can't negative numbers.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -