Home > Back-end >  Help: about vector in C memory allocation issues
Help: about vector in C memory allocation issues

Time:09-27

Using the vector in the main function defines a two dimensional array (this definition is the cause of the first dimension array length is known, but the second dimension length unknown) :
 vector MainColorVec (RegionNum vector (0));//RegionNum has calculated 


Then, the array in the function call:
 Segment IMG.//defines a Segment the object of the class 
IMG. GetRegionMainColorVecs (RegionNum LabelVec, AreaVec, 8, MainColorVec, MainColorFreqVec, MainColorNumVec);


Among them, the member function declaration is as follows:
 class Segment 
{
Private:
.//a member variable

Public:
.//a member function
Void GetRegionMainColorVecs (int RegionNums, int * LabelVec, int * AreaVec, const int binNums, vector MainColorVec, float * MainColorFreqVec, int * MainColorNumVec);
}



The problems is the 2 d array MainColorVec calculation results without passing out , specific as follows:
Call a function within:

After the jump function:


Consult everybody ~ ~ great god what causes

CodePudding user response:

Parameter is changed to a reference type

 void GetRegionMainColorVecs (int RegionNums, int * LabelVec, int * AreaVec, const int binNums, vector & MainColorVec, float * MainColorFreqVec, int * MainColorNumVec); 

CodePudding user response:

reference 1st floor akirya response:
parameter instead of a reference type

 void GetRegionMainColorVecs (int RegionNums, int * LabelVec, int * AreaVec, const int binNums, vector & MainColorVec, float * MainColorFreqVec, int * MainColorNumVec); 


The result is right, thank you!
But, what are the reasons? Also please tell ~
  • Related