knn icon indicating copy to clipboard operation
knn copied to clipboard

std::pair<double, int> squaredDistances[data->rows];

Open M-youyou opened this issue 9 years ago • 1 comments

I have a question in knn.cpp file and in 26th rows: std::pair<double, int> squaredDistances[data->rows];

The length of array squaredDistances is not sure. How does this implement?

My compile environment is VS 2013.

M-youyou avatar Oct 18 '16 07:10 M-youyou

Hi there,

That is a good point. The length of squaredDistances is dynamic, which is ok when compiling with g++, but it seems that the Visual Studio compiler does not handle it. You can use the function "alloca" instead, to allocate the array on the stack.

Reference: http://stackoverflow.com/questions/312116/c-array-size-dependent-on-function-parameter-causes-compile-errors#312125

luizgh avatar Oct 23 '16 16:10 luizgh