I am having trouble getting some code to compile. The problem seems to be with assigning an array reference to an element of a struct. Here is the code below, and the error message.
So I have a struct that looks like this
struct numpyFormatterData{
double* pointerToNumpyData;
unsigned long numberOfDataRows;
unsigned long numberOfDataColumns;
std::string delimitedStringOfColumnNames;
};
Then I have a function that generates a random 50x10 array of doubles.
double generateRandomArray(double lower_, double upper_)
{
int row = 50;
int columns = 10;
double arr[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
arr[i][j] = std::uniform_real_distribution<double>(lower_, upper_)(gen);
}
}
return arr;
}
In my test case I have the following code which is causing the problem. I am using the Catch testing framework.
TEST_CASE( "Test construction of NumpyDataRequest Class", "[NumpyDataRequest]" ) {
SECTION( "Test factory method for creating NumpyDataRequest" ) {
double testDataArray = generateRandomArray(0.0, 2.0);
numpyFormatterData testNumpyRequest;
testNumpyRequest.numberOfDataRows = 50;
testNumpyRequest.numberOfDataColumns = 10;
testNumpyRequest.delimitedStringOfColumnNames;
testNumpyRequest.pointerToNumpyData = &testDataArray; //PROBLEM HERE
std::unique_ptr<NumpyDataRequest> testingDataRequest = NumpyDataRequest::setDataForRequest(testNumpyRequest);
numpyFormatterData checkDataRequest = testingDataRequest->getRequestData();
REQUIRE(checkDataRequest.numberOfDataColumns == 10);
}
}
The error message I am getting is:
undefined reference to `generateRandomArray(double, double)'
collect2: error: ld returned 1 exit status
I know that I am trying to assign the reference to testDataArray incorrectly. I have tried a variety of different ways to do this, but none have worked. Any suggestions?