Please look at my code below:
class SVMClassifier : public LibHAR
{
public:
...
//This is my function returning a pointer to pointer to svm_node structure
svm_node** SVMFeatureExtraction(SkeData* inputData, int* pFrameNum, int* pFeatureNum, double wt);
//This function calls SVMFeatureExtraction
virtual bool FeatureExtraction(SkeData* inputData, const double* dataLabels = NULL, int labelNum = 0); //This function calls SVMFeatureExtraction
...
private:
svm_node** SVMNodes;
int dataNum;
...
}
svm_node** SVMClassifier::SVMFeatureExtraction(SkeData* inputData, int* pFrameNum, int* pFeatureNum, double wt)
{
*pFeatureNum = FEATURENUM;
*pFrameNum = inputData->GetFrameSaved();
svm_node** pNodes = new svm_node*[*pFrameNum];
for (int i = 0; i < *pFrameNum; i++)
{
pNodes[i] = new svm_node[FEATURENUM + 1];
for (int j = 0; j < FEATURENUM / 3; j++)
{
FEATURE_VEC* pVec = new FEATURE_VEC;
if (!CalFeatureVector(inputData, i+1, j+1, pVec, wt))
return NULL;
pNodes[i][j*3].index = j*3 + 1;
pNodes[i][j*3].value = pVec->x;
pNodes[i][j*3 + 1].index = j*3 + 2;
pNodes[i][j*3 + 1].value = pVec->y;
pNodes[i][j*3 + 2].index = j*3 + 3;
pNodes[i][j*3 + 2].value = pVec->z;
delete pVec;
}
pNodes[i][FEATURENUM].index = -1;
pNodes[i][FEATURENUM].value = 0;
}
return pNodes;
}
bool SVMClassifier::FeatureExtraction(SkeData* inputData, const double* dataLabels, int labelNum)
{
CleanNodes();
int n;
SVMNodes = SVMFeatureExtraction(inputData, &dataNum, &n, actWeight); //Error here!
...
}
The class method FeatureExtraction calls another method SVMFeatureExtraction which returns a pointer to pointer. I think the memory pointed by the pointer is allocated dynamically in the heap, since it is created by "new" . But when I debugged the program, the address returned by SVMFeatureExtraction can not be successfully assigned to SVMNodes(SVMNodes is always "NULL"), although the content of pNodes is correct. Can anyone tell me what is wrong with the code?
Thank you.
SVMFeatureExtractiontry to print casted to int value ofpNodes, also printSVMFeatureExtraction(inputData, &dataNum, &n, actWeight)without assigning.inputData->GetFrameSaved()returns a value > 0? Also, are you sure thispNodesis allocated memory insideSVMFeatureExtraction()