Note that there are some explanatory texts on larger screens.

plurals
  1. POFunction returning pointer to pointer
    primarykey
    data
    text
    <p>Please look at my code below:</p> <pre><code>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-&gt;GetFrameSaved(); svm_node** pNodes = new svm_node*[*pFrameNum]; for (int i = 0; i &lt; *pFrameNum; i++) { pNodes[i] = new svm_node[FEATURENUM + 1]; for (int j = 0; j &lt; 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-&gt;x; pNodes[i][j*3 + 1].index = j*3 + 2; pNodes[i][j*3 + 1].value = pVec-&gt;y; pNodes[i][j*3 + 2].index = j*3 + 3; pNodes[i][j*3 + 2].value = pVec-&gt;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, &amp;dataNum, &amp;n, actWeight); //Error here! ... } </code></pre> <p>The class method <code>FeatureExtraction</code> calls another method <code>SVMFeatureExtraction</code> 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 "<code>new</code>" . But when I debugged the program, the address returned by <code>SVMFeatureExtraction</code> can not be successfully assigned to <code>SVMNodes</code>(SVMNodes is always "NULL"), although the content of <code>pNodes</code> is correct. Can anyone tell me what is wrong with the code?</p> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload