2017-09-27 55 views
0

我想顯示一個結構向量的內容。 但我得到的問題顯示它們沒有匹配函數來調用'funciton'/將一個結構向量傳遞到函數

這是我的結構

struct tDetection { 
     tBox box; // object type, box, orientation 
     double thresh; // detection score 
     double ry; 
     double t1, t2, t3; 
     double h, w, l; 
}; 

功能,顯示結構

void displayDetection(struct tDetection& param) { 
    cout << param.type << param.x1 << param.y1 << param.x2 << param.y2 << param.alpha << endl; 
    cout << param.thresh << param.ry <<endl; 
    cout << param.t1 << param.t2 << param.t3 <<endl; 
    cout << param.h << param.w << param.l << endl; 
} 

當我運行這個功能,錯誤信息:沒有用於調用「displayDetection」的匹配函數。

調用顯示功能

bool eval(){ 

// set some global parameters 
    initGlobals(); 

    // ground truth and result directories 
    string gt_dir   = "/Users/Documents/c++/eval_too/eval_too/data/object/lable_2"; 
    string result_dir  = "/Users/Documents/c++/eval_too/eval_too/result/result_sha"; // results 
    string plot_dir  = result_dir + "/plot"; 

    // create output directories 
    system(("mkdir " + plot_dir).c_str()); 

    // hold detections and ground truth in memory 
    vector< vector<tGroundtruth> > groundtruth; 
    vector< vector<tDetection> > detections; 

    bool compute_aos=true; 
    vector<bool> eval_image(NUM_CLASS, false); 
    vector<bool> eval_ground(NUM_CLASS, false); 
    vector<bool> eval_3d(NUM_CLASS, false); 

    // for all images read groundtruth and detections 
    for (int32_t i=0; i<N_TESTIMAGES; i++) { 

     // file name 
     char file_name[256]; 
     sprintf(file_name,"%06d.txt",i); 

     // read ground truth and result poses 
     bool gt_success,det_success; 
     vector<tGroundtruth> gt = loadGroundtruth(gt_dir + "/" + file_name,gt_success); // ** just follow them; no need to change 
     vector<tDetection> det = loadDetections(result_dir + "/data/" + file_name, 
                compute_aos, eval_image, eval_ground, eval_3d, det_success); // ** change to my format 

     // ** add element to the vectors 
     groundtruth.push_back(gt); 
     detections.push_back(det); 

     // check for errors 
     if (!gt_success) { 
      // mail->msg("ERROR: Couldn't read: %s of ground truth. Please write me an email!", file_name); 
      cout << "ERROR: Couldn't read ground truth of file : " << file_name << endl; 
      return false; 
     } 
     if (!det_success) { 
      //mail->msg("ERROR: Couldn't read: %s", file_name); 
      cout << "ERROR: Couldn't read detection of file : " << file_name << endl; 
      return false; 
     } 
    } 

    displayDetection(detections[0]); 
} 
+2

'detections [0]'是'std :: vector ',而不是'tDetection'。 – Mark

+0

它是一個嵌套向量。該函數只需要'tDetection',你不需要'struct'。 –

+0

void displayDetection(tDetection&param){...}這是你的建議嗎? – Wes

回答

0

detections[0]給你一個const& tdetection另一個功能;但是你的函數聲明爲非const:void displayDetection(struct tDetection& param)

將其更改爲void displayDetection(const struct tDetection& param),它將起作用(並且它確實不需要非常量,因爲除讀取它外,您沒有做任何事情)。

+0

我仍然得到相同的錯誤輸出。 – Wes

相關問題